Jump to content

File Upload Script


N-Bomb(Nerd)

Recommended Posts

Hello,

 

I'm planning on making a website where people are able to upload files and directly link to them. Ideally, I want to keep the same file names that the people use when they upload the file. I was planning on keeping the directory that stored all of the files outside of the www directory and disable execute permissions. However, how would I avoid file overwriting with the same file name?

Link to comment
Share on other sites

file_exists, perhaps.

 

I'm aware of that function, but I was just wondering how to avoid the conflict. I've never had to store files into a directory and I didn't know if there was method that I could use to avoid overwrites. Perhaps the main upload directory has a series of additional sub-directories as well. I'm not sure that's why I'm trying to get ideas. :D

Link to comment
Share on other sites

I personaly would give each user a sub directory, and you must check if the file exists if you do not want to do a blind over write.  what conflict are you concerned about?

 

Giving each user a sub-directory is a pretty good idea. I understand about using file_exists, but I still want to accept every file that's uploaded using the original file name without overwriting any files.

Link to comment
Share on other sites

I personaly would give each user a sub directory, and you must check if the file exists if you do not want to do a blind over write.  what conflict are you concerned about?

 

Giving each user a sub-directory is a pretty good idea. I understand about using file_exists, but I still want to accept every file that's uploaded using the original file name without overwriting any files.

then you will have to ensure that every user only uploads a file once under any given name.  If you can exert that level of control over your users do please tell us how you do it ;D  The only real option that I can see is to check for the file existing and then either append something to the end of the new one, or present options to the end user on what they want to do about it - overwrite/rename new/rename old/cancel... if there is already a file with that name.

Link to comment
Share on other sites

I would personally store file information in a database, and give the file a unique name (also stored in the database).

 

1) Create a unique filename

2) if unique name exists, go to step 1

3) store file info, and unique filename in database.

 

With a download script to give the proper filename :)

 

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.