Quote:
Originally Posted by SilentSpic
Okay, since the code above won't work. Can someone lead me in the right direction? I've been looking around for a least 5 hours now.
|
First things first:
If you're trying to keep people from stealing your images, don't put them online. Putting it into a file isn't going to help stop anyone but the most idiotic surfer. All you'll be doing is adding needless overhead to your site by requiring it to open & read and write files all the time. If your site is popular, this will increase the amount of memory being used up. This is because what you're trying to do is essentially reading all the binary data from an image into one big string. Only then will it be written to file.
Second, ANY display of an image on a web page needs to be done using the <img> element. yes, it can be done with <object> if you're a masochist and want to overcome all the browser compatibility nightmares. So all a surfer has to do is find the path to the file (whether it is a PHP file or a real image file) and there he can download your file. If you think displaying it in PHP will overcome theft you're wrong.
In case you've made it this far and don't care about what I've said, here ya go:
PHP Code:
<?php
$teh_img = "/path/to/image.jpg";
// Do some magic to find the MIME type
// Also do magic to find the image size
// More on that elsewhere in my post
// Set the content type
header("Content-type: $mtype"); // where $mtype is the MIME type from above
// Set the image size
header("Content-Length: $img_size"); // where $img_size is the size of the image
$handle = fopen($teh_img, "r") or die("Cannot open $teh_img");
while (!feof($handle))
{
$data=fgets($handle, 900);
echo $data;
}
fclose($handle);
?>
Code above is untested.
I skipped over the part where you get the mime type and the image size. Image size is easy to get. Getting the MIME type is more involved and hey, if you want me to write the whole thing for you, you can pay me. ;-)
The code above needs to be saved as its own file. Then you call it as any other image in your HTML.