Silver Posted November 2, 2006 Share Posted November 2, 2006 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! Quote Link to comment Share on other sites More sharing options...
fenway Posted November 2, 2006 Share Posted November 2, 2006 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. Quote Link to comment Share on other sites More sharing options...
gluck Posted November 2, 2006 Share Posted November 2, 2006 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? Quote Link to comment Share on other sites More sharing options...
Silver Posted November 2, 2006 Author Share Posted November 2, 2006 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 :) Quote Link to comment Share on other sites More sharing options...
fenway Posted November 2, 2006 Share Posted November 2, 2006 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). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.