Jump to content

inserting image path into database


Silver

Recommended Posts

Hi,

I am working on a script which inserts text fields into a database and also uploads an image into a directory with the same form. The text fields insert fine and the image uploads, but I can't get the image path into the database. The closest I've come is getting it to do a /tmp/php2308jhl kind of thing.

I've just picked up this project again after a couple of years and most of my knowledge has deserted me so I'm fumbling about in the dark rather.

How do I get it to put the path into the database?


Also, after I've sorted this I also want to be able to upload two different files using the same form, what do I need to do to allow multiple file uploads?

Thanks!
Link to comment
Share on other sites

It's amazing how many times this issue comes up... maybe we need a sticky.

Your PHP script stores the file somewhere -- you obviously know that path.  This path is a string, so store it as such into a database field of your choice.  I would recommend using relative pathnames for flexibility.
Link to comment
Share on other sites

Use relative or absolute-- up to you. Have an upload path defined in config files as it will be static most of the time. You could use that path from the config. The images should always be renamed while uploading to the server. Also have you tried storing images in the database? like a Blob?
Link to comment
Share on other sites

Thanks :)

I thought it would've been asked before so I did do a search but there were so many results to wade through, I did start but couldn't find what I was after so I thought it'd be quicker to ask!

I half solved my problem - now the file names are going into the database but only as their filename, not as the path - which, as they're in a subdirectory, means I have to do images/$file which isn't a problem from my point of view as long as it won't cause any problems? Plus it isn't actually what I wanted to do - get the path in the database! But if it works for displaying images on another page (which it seems to) it's fine...

The images aren't being renamed upon uploading, what do I need to do to fix that?

Also is there a way of restricting image size as in pixels as well as kbs? If so what do I need to do?

Thanks again :)
Link to comment
Share on other sites

You can "safely" rename the user-supplied filename by converting sensitive characters, or just it your own unique name.  Doesn't really matter, no one will see it anyway; but it's nice to have the user's name around as well, just in case.  As for pixel restrictions, you could enforce them on the upload size, assuming you have access to a server-side module that can read images (ImageMagick/GD).
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.