user1226372
user1226372

Reputation: 45

Storing the path of multiple files using PHP

I am working on an application, where the user has to upload files in a cart.e.g. the user upload the file "A" and now doing different work. After some time he again upload another file, file "B". How I can manage the file path or store the file path, as if I use move_uploaded_file() function, then it can overwrite the other user's file with same file name.

Thanks.

Upvotes: 0

Views: 196

Answers (3)

fmask
fmask

Reputation: 481

Create folder run time against session id, that way only current session user files goes to the folder.

temp_uploads/ (main uploads folder)

temp_uploads/_jhk43543h5h435k3453 (session id folder for user 1)

temp_uploads/_jhk43543h5h435k34tr (session id folder for user 2)

temp_uploads/_jhk43543h5h43trtrtg (session id folder for user 3)

you just need store session id for each user, which you maybe you are already doing.

happy Coding :)

Upvotes: 0

Pete
Pete

Reputation: 1309

When I've had this issue, I have used a timestamp added to the filename. Usually I want to cleanse the filename anyway, so I

  1. replace characters I don't like
  2. remove the file extension and check it looks OK (e.g. pdf not exe)
  3. add a timestamp to the filename
  4. put the extension back on

Obviously, this isn't suitable in every instance, but it might give you some ideas.

Upvotes: 1

Yanki Twizzy
Yanki Twizzy

Reputation: 8001

You use php's time function to generate a timestamp that you append to the filename so that they can be different. Then you can use a column in the db to store the file paths. You could store all the file paths in the same column but separate each one with ; or any other character. To get the separate paths, you can use php's explode function.

Upvotes: 0

Related Questions