Jump to content


Photo

Displaying images from database and saving as with the right name!


  • Please log in to reply
4 replies to this topic

#1 merrydown

merrydown
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 October 2006 - 05:54 PM

Hi, I am storing images in a database for use on a website.  The problem is that when I try to save an image I am displaying on the page, the script name is the save name. (  The image src is typically: "view.php?imageID=3&size=thumb".  The code / headers in the script view.php which displays the images are:

if (!empty($row_imageRS['image'])){
    // Output the MIME header
    header("Content-Type: {".$row_imageRS['mimeName']."}");
$latifah=$row_imageRS['name'];
if ($_GET['size']=='main') {
// Output the image
    echo $row_imageRS['image'];}
if ($_GET['size']=='thumb') {
// Output the image
    echo $row_imageRS['thumb'];}
}

My question is, how do I get the displayed image to right-click save as $row_imageRS['name'] ?

Cheers for any help offered!

Jim

#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 17 October 2006 - 06:46 PM

Don't store the images in the database.
Store the images in a folder on the server, reference that with the name of the image, and hte path.
It's a lot easier, cleaner, and a whole lot better on performance.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 merrydown

merrydown
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 October 2006 - 07:02 PM

Thanks for the advice.  Point taken.  Is there a way to pass the name though?  On the size of system I am dealing with, the performance hit isn't a big deal and I'd just like to know if anyone can help me?

#4 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 17 October 2006 - 07:04 PM

You can't do what you are wanting from the database.

THe way you see people being able to right click on a file, and save file as, is when the file is on the server, that way the server can recognize the file type naturally and allow there browser to do that.

As I said as long as you are doing it that way you are stuck, there are a lot of reasons you don't want to put images/files into a database.
Even text files.

I would rewrite your system, it would allow a lot more functionality in the future, and also get you what you are trying to do naturally just by displaying a link to the path location of the file directly through the html.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#5 merrydown

merrydown
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 October 2006 - 08:17 PM

Thanks for the explanation businessman, it wasn't explicit in your initial post that it wasn't possible.  It sounded like you were saying it was bad practice.  It won't take much work to do it the other way, I converted it from file storage to database in the first place, so no biggy.

Cheers again, Jim




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users