Page 1 of 1

How to get images from a database and display the image?

Posted: Fri Sep 24, 2004 1:29 am
by ravervx
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

Posted: Fri Sep 24, 2004 1:37 am
by feyd
read the [php_man]header[/php_man] function page, or search here about [devnet]+force +download[/devnet]

Posted: Fri Sep 24, 2004 10:50 am
by pickle
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.

Posted: Fri Sep 24, 2004 11:29 am
by ravervx
thanks for the answer
Actually, right now I'm storing the pictures in the file system. But I renamed them with a randomly generated name for security.

Posted: Fri Sep 24, 2004 11:41 am
by pickle
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.

Posted: Fri Sep 24, 2004 12:10 pm
by feyd
for more info on the images and databases type stuff: [devnet]+image +database -pag*[/devnet]

Posted: Fri Sep 24, 2004 1:24 pm
by ravervx
Thanks feyd and pickle, you guys are a great help

Posted: Fri Sep 24, 2004 2:31 pm
by ravervx
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

Posted: Fri Sep 24, 2004 3:05 pm
by pickle
I don't know if this is necessary, but I always put my filepath in quotes.

Posted: Fri Sep 24, 2004 3:18 pm
by ravervx
Sorry, when I wrote the example I forgot the quotes around the filename.
It suppose to be require_once("config.php");
But I guess the orignal question still stands

Thanks

Posted: Fri Sep 24, 2004 3:24 pm
by pickle
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.

Posted: Fri Sep 24, 2004 3:52 pm
by feyd
your include_path either needs adjusting or you aren't including/requiring in the right path.. check the output of your phpinfo(), or use $_SERVER['DOCUMENT_ROOT'] to get the web root of your site.

Posted: Thu Oct 28, 2004 9:15 pm
by ravervx
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.

Code: Select all

header("Content-type: &#123;$type&#1111;'mime']&#125;");
header("Content-disposition: filename=$filename");
header("Content-length: " . filesize($image));
return readfile($image);
Is there any fix for it? Or there is something I'm missing?

Thanks