Reputation: 23
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.
Upvotes: 0
Views: 48
Reputation: 74220
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.
Upvotes: 2