How to get images from a database and display the image?
Moderator: General Moderators
How to get images from a database and display the image?
I'm writing a web gallery. All the pictures are saved in a database. I can retrive the images fine, by using <img src="diaplay.php"> to dislay images. Where the diaplay script would get the binary data from the database and convert it into a jpeg and return it to the browser.
But this way, when the user try to save the image, it gets display.php as the file to save. I have the original picture filenames saved in the database. How can I return the image files with thier original file names? By using a javascript or something of sort?
Please help.
Thanks
But this way, when the user try to save the image, it gets display.php as the file to save. I have the original picture filenames saved in the database. How can I return the image files with thier original file names? By using a javascript or something of sort?
Please help.
Thanks
Ya, what ~feyd said. In other news - I wouldn't suggest storing the images in the DB if this gallery is going to be used too much. Storing images in the DB is cool and does simplify some things, but in my experience, page load times do increase quite a bit.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
I think the best solution would be to store the images in a directory outside the document root. Then, the images can't be viewed by simply typing in their URL. You can still use a display.php type file, but that would dump the data from the filesystem, rather than the DB.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
One more question,
I can't seemed to use require_once() to include files in an upper level directory
For example, config.php is within the folder /
and the file using config.php is within /folder/filetouseconfig.php
I used syntax
require_once(../config.php);
But that does not work, I checked the manual for the function, but nothing is mentioned regarding that.
Thanks
I can't seemed to use require_once() to include files in an upper level directory
For example, config.php is within the folder /
and the file using config.php is within /folder/filetouseconfig.php
I used syntax
require_once(../config.php);
But that does not work, I checked the manual for the function, but nothing is mentioned regarding that.
Thanks
Requiring (sp?) is a fatal error, so if it's not working, what error does it display? If it doesn't display an error, then the requiring is working and you may need to check the file you're requiring.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Hi,
Since the last time I posted the original question, I have written up my php script. But recently I was doing testings in IE 6.0 and though the image loads, when I right click on it to save, it saves as untitiled type bmp.
Is there any fix for it? Or there is something I'm missing?
Thanks
Since the last time I posted the original question, I have written up my php script. But recently I was doing testings in IE 6.0 and though the image loads, when I right click on it to save, it saves as untitiled type bmp.
Code: Select all
header("Content-type: {$typeї'mime']}");
header("Content-disposition: filename=$filename");
header("Content-length: " . filesize($image));
return readfile($image);Thanks