Re: binary data in php
| From: | Marek Kilimajer | Date: | Fri, 16 Apr 2004 13:26:50 +0000 |
| Subject: | Re: binary data in php | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-183621@lists.php.net to get a copy of this message | ||
Anthony Ritter wrote:
However when clicking the getdata.php link - the file does not appear on the screen. The code is below. Thank you for your time. TR ..................... //getdata.php <? if($_GET['id']==1) { @myql_connect("localhost","root","mypass");Remove @'s while debugging.
@mysql_select_db("sitename");
$query = "SELECT bin_data,description,filetype
FROM binary_data
WHERE id=1";
$result = @mysql_query($query);
$data = @mysql_result($result,0,"bin_data");
$description = @mysql_result($result,0,"description");
$type = @mysql_result($result,0,"filetype");
Header( "Content-type: $type");
echo $data."<br>";
echo $description."<br>";
The above cannot work. You cannot mix binary data with html.
}
else
{
@mysql_connect("localhost","root","mypass");
@mysql_select_db("sitename");
$query = "SELECT bin_data,description,filetype
FROM binary_data
WHERE id=$id";
----------------------^^
register globals are off, and the variable is not validated - can contain anything
$result = @mysql_query($query); $data = @mysql_result($result,0,"bin_data"); $description = @mysql_result($result,0,"description"); $type = @mysql_result($result,0,"filetype"); Header( "Content-type: $type"); echo $data."<br>"; echo $description."<br>"; } ?>