N-Bomb(Nerd) Posted January 12, 2012 Share Posted January 12, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/254890-file-upload-script/ Share on other sites More sharing options...
Pikachu2000 Posted January 12, 2012 Share Posted January 12, 2012 file_exists, perhaps. Quote Link to comment https://forums.phpfreaks.com/topic/254890-file-upload-script/#findComment-1306928 Share on other sites More sharing options...
N-Bomb(Nerd) Posted January 12, 2012 Author Share Posted January 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/254890-file-upload-script/#findComment-1306933 Share on other sites More sharing options...
Muddy_Funster Posted January 12, 2012 Share Posted January 12, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/254890-file-upload-script/#findComment-1306940 Share on other sites More sharing options...
N-Bomb(Nerd) Posted January 12, 2012 Author Share Posted January 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/254890-file-upload-script/#findComment-1306948 Share on other sites More sharing options...
Muddy_Funster Posted January 12, 2012 Share Posted January 12, 2012 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 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. Quote Link to comment https://forums.phpfreaks.com/topic/254890-file-upload-script/#findComment-1306952 Share on other sites More sharing options...
laffin Posted January 12, 2012 Share Posted January 12, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/254890-file-upload-script/#findComment-1306969 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.