0

i an trying to get the result(image) from url but there is some thing error in the code my code is:

<?php
if(isset($_POST['submit']))
{
$url= $_POST['url'];
$qrurl= 'http://www.qr-code-generator.com/phpqrcode/getCode.php?
cht=qr&chl='.$url.'&chs=180x180&choe=UTF-8&chld=L|0';
$result = file_get_contents("$qrurl");
echo $result;
}
else
{
echo"<form method='post' action='index.php' >
<input name='url' class='material' placeholder='Enter url...' type='url'autofocus/></br><br>
<input name='submit' id='submit' type='submit' value='submit'/></br><br>
</form>
";
}
?>

the above code displays nothing but when i open the url in browser it displays qr code.

1 Answer 1

2

You need a (PNG) header since that is the type of file it is creating, and to make sure the URL is in one line and not broken into two; very important.

<?php 
if(isset($_POST['submit']))
{
$url= $_POST['url'];
$qrurl= 'http://www.qr-code-generator.com/phpqrcode/getCode.php?cht=qr&chl='.$url.'&chs=180x180&choe=UTF-8&chld=L|0';
$result = file_get_contents("$qrurl");
echo $result;

header ('Content-Type: image/png');
exit;

}
else
{
echo"<form method='post' action='index.php' >
<input name='url' class='material' placeholder='Enter url...' type='url'autofocus/></br><br>
<input name='submit' id='submit' type='submit' value='submit'/></br><br>
</form>
";

}

You may also have to add ob_start(); at the top after the opening <?php.

And that the file is not encoded with a byte order mark. This too will throw an error.

The file can be encoded as ANSI or UTF-8 without BOM.

Sign up to request clarification or add additional context in comments.

2 Comments

errors:" failed to open stream: Connection timed out" and"Cannot modify header information"
@SriCharan Go over my answer again; I made a few edits. Follow them completely. This is an encoding issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.