Jump to content

How to save an image stored in a database?


taketwodevelopment

Recommended Posts

Hello all,

 

Actually 2 quesitons here.

 

1. I have a client that has a system that he uses to store pictures in a mysql database, along w/ other things about the pictures.  He now wants the pictures stored on a different box.

I have a script I wrote to pull the images from the database and display them - but how can I pull them out and save them as a file?

 

2.  The way the above said images get into the database, is someone wrote a crawler script for him that goes to several sites and pulls images off (he does have the sites permission to do so).  After looking at the script-  the person that wrote it gets the url of the image and then does a curl on it - then shoves the curl result into the database.

 

Since I have the remote URL already, what is the best way to get that image stored on the box that the crawler is running on?  Doing some searching, Im thinking to just do a imagecreatefromjpeg or gif, but Im not sure if the GD librarys are installed on that box.  Im betting they are not.  So if that is the case, could anyone offer other options?

 

(please no flames about storing pics in the database, Im just trying to clean up someone elses mess)

 

Thanks

_Rob

 

 

 

how is the image stored? in a blob as the raw file data it sounds like that's what you're saying? if so, just do

file_put_contents('some/file/path/image.jpg', $imageDataFromDatabase); // Don't use such a long variable name

 

I don't understand your second question.

for part 2:

 

dunno it blob images need to be imagecreatefromjpegED but i have an upload script that if you provide a new name and use the rename() function it will save the file as that new name without any gd functions. Also, I wouldnt use the remote url, because there is no guarantee that the image is still in the remote location, so use whats in the db because it is there for sure.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.