Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to be able upload pictures to a folder and their filepaths to a MySQL database without creating multiple records.

For example instead of:

id    PicturePath                  size
1     file1.jpg                    90832
2     file2.jpg                    84593

I want to do:

id    PicturePath1                 PicturePath2                 PicturePath3
1     file1.jpg                    file3.jpg                    file5.jpg  

And also as it uploads, it should change the name of the original file e.g. if User uploads DSC0009.jpg it should upload into the file upload folder and MySQL Database as: someRandomFileName8087935.jpg

share|improve this question

migrated from Nov 17 '12 at 10:31

This question came from our site for professional and enthusiast programmers.

if you want to change the file name just use $name = RAND(); I don't think you can inset file names into one row only, maybe you can use the update statement, but that is a bit beyond my php skill to orient.

share|improve this answer

(if this is not what u have asked comment ur question again)

okay what i understand is.

1) to create a random name you can use time() in name of file because random function has the probability that two files names could be same (if that could be a problem with your system). e.g.

time().$_FILES["uploadPic"]["name"] // if file name is john.jpg
it will save file name something like 1302827272john.jpg

2) i am not clear what u have asked... but this might help..

it would be better if u use multiple columns for picturePaths for one record but if you have only one column of picturePath then you can update the previous field by apending new file name with old file name.. for example

// get old path using 
Select picturePath as path 
From your_table_name 
where = '1';

$path = path.','.$newFileName; // this is suedo code

// update your picture path using update query
update table_name SET picturePath = $path where id = '1'

and remember now you have to split picture paths when u will use it you can use preg_split

preg_split('/,/', $path, -1, PREG_SPLIT_NO_EMPTY);
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .