note 51914 deleted from function.imagepng by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 10:18:02 +0000 |
| Subject: | note 51914 deleted from function.imagepng by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-196989@lists.php.net to get a copy of this message | ||
Note Submitter:
----
To cbrasho at yahoo dot com
I have read your note and the note that was made in reply. My SIMPLE solution is to add a key to
each image record in the database so that the ID+Key pair will be used very similarly to a
Username+Password pair =) all you have to do is create a unique random number or something to put in
the "Key" field of the database when the entry is made.
i've modified the code and pasted it here...
<?php
//get file ID+Key
$id = $_REQUEST['id'];
$key = $_REQUEST['key']; // i added this!
//get data from blob
$sql = "SELECT Data, Type, Extension FROM Images WHERE ID=$id AND Key=$key"; // this is
the clever bit =D
$records=mysql_query($sql);
$record=mysql_fetch_row($records);
$data=$record['Data'];
$type=$record['Type'];
$ext=$record['Extension'];
//output data
header("Content-Type: $type");
header("Content-Disposition: inline; filename=img$id.$ext");
echo $data;
?>
all i did was add 1 line and change another =D
now if "image.php?id=1&key=A29F1X" gives a result,
"image.php?id=2&key=A29F1X" will output an image of zero bytes in size because the
keys in the database are unique =)