1

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

0

2 Answers 2

0

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.

0

(if this is not what you have asked comment your 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. It's not clear what you have asked, but this might help.

It would be better if you 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 appending new file name with old file name. For example:

// get old path using 
Select picturePath as path 
From your_table_name 
where your_table.id = '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 you will use it you can use preg_split

preg_split('/,/', $path, -1, PREG_SPLIT_NO_EMPTY);

You must log in to answer this question.

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