Forums

This topic is locked

Can't display jpg from SQL database

Posted 09 Feb 2008 23:16:12
1
has voted
09 Feb 2008 23:16:12 Patrick Houlihan posted:
I have properly set-up a SQL database. I'm able to store jpg along with descriptions. I can see them in the database after I upload them to the database. However, when I try and display the pictures, via dreamweaver, using an image field, the pictures are displayed on my webpage properly, but that is because it it retrieving them off of my local drive in lieu of my SQL database. The pictures only display if I use my computer, any other computer, the pictures are not displayed.

Furthermore, when I test my recordset, it does show the propoer descrioption, though the column where I set up to store the images shows the path to where the picture was originally uplaoded from, i.e. c:\.... Now I'm not sure if this is screwing things up, but who knows.

Basically, what do I need to do to have dreamweaver properly instruct my website to display a jpg, located on my sql database without having it point to the location where the photo was uploaded from?

Any help is greatly appreciated!

Replies

Replied 10 Feb 2008 16:03:03
10 Feb 2008 16:03:03 Alan C replied:
Hi Partick

I'm not sure whether you have the whole of the image going into the database as blob type data or the image name, as you say they work off your local machine it could be that the path is not quite right. I did something like this a while ago and rather than putting the whole image into the database I put just the filename, then stored the images in folders. I did that after some reading around on the subject and concluded that because I am running off a shared server, there would be a lot less traffic in and out of the database doing it that way. It means that mysql only has to handle a few bytes of the filename rather than whatever size the image it, and as there are lots of images on some of my pages I liked that idea.

Something I'm working on at the moment has been giving me great pain - php accessing images, resizing them and then using them to build a page that will be static once built. I've had quite a struggle to sort out the full path to the image that's needed in some cases and the www path that is needed elsewhere.

Sorry that doesn't sort out your problem but it might trigger something for you or someone else <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Replied 10 Feb 2008 20:30:49
10 Feb 2008 20:30:49 Patrick Houlihan replied:
Aftr further investigation. it is only the file name that is being stored on the database. So you recommend that I store the images on folders in lieu of the database?

I want a users to have the ability to upload a picture to his/her profile. How do I make this occur dynamically? That is, how do I store the picture in a folder? Also, how do I build my recordset off of a folder in lieu of a database?

BTW - when a new user registers on my site, how do I have a new page auto-generated and tagged in such a way that is unique to that user?
Replied 10 Feb 2008 20:33:05
10 Feb 2008 20:33:05 Patrick Houlihan replied:
BTW - Alan thanks for your reply before!

-P
Replied 11 Feb 2008 18:43:37
11 Feb 2008 18:43:37 Alan C replied:
Hi
I can outline the process but at the moment can't post a lot of code as I am behind with a development job, what you need is an image uploader, you can do it with a form that will allow people to browse on their machine and select the image to upload, then upload it. You will need something like this . . .

<pre id=code><font face=courier size=2 id=code>&lt;form method="post" enctype="multipart/form/data" name="form_g" id= "form_g" action = to your script&gt;
&lt;input type="hidden" name="Max file size" value="6291456"/&gt;
&lt;input type="file" name=""most_recent" size="50"&gt;
&lt;input type="submit" name="Submit" value="upload_image"&gt;
</font id=code></pre id=code>that is not exact, you would have to search around and sort out the exact details

then you need a script that receives the file, it goes into the system and you pick it up then there is a php function called move_uploaded_file() that checks the uploaded image

once you know it's there on your server you really need to do some checking on it, who knows what someone might upload - use function getimagesize() to find out the type of file and size that is uploaded, in the form above people can send an image up to 6291456 bytes long, I think that's 6MB, then you will need to use something like imagemagick to resize it to whatever you want, then finally put the name into your database together with a path

Sorry that's brief - there are other and better ways of getting your image up, that just happens to be how I did mine some time ago.

I did all sorts of checks to make sure the aspect ratio was reasonable too, what is someone sends a 1 pixel wide by 600 high? you know what some people are like

hope that helps

Reply to this topic