dannybrazil Posted September 15, 2009 Share Posted September 15, 2009 Hello I have a question about uploading files to server why we need(or just do) changing the names of a file that was uploaded to the server what is the difference between : 1234.jpg or 1234_another_name.jpg Thanks Link to comment https://forums.phpfreaks.com/topic/174343-upload-file/ Share on other sites More sharing options...
Garethp Posted September 15, 2009 Share Posted September 15, 2009 Why do we change the name? We usually attach an ID tag to the name so that we don't overwrite a file that has the same name. Say I upload a picture of Australia with the name "country.jpg", and then one of South Africa called "country.jpg". The South Africa photo would overwrite the Australia photo. So instead, I'd upload the first one and my script would change it to "1 country.jpg" and the South Africa photo would be changed to "2 country.jpg" but that's just me. I like to store uploaded files into a database and append their ID to the beginning of their name Link to comment https://forums.phpfreaks.com/topic/174343-upload-file/#findComment-919010 Share on other sites More sharing options...
dannybrazil Posted September 15, 2009 Author Share Posted September 15, 2009 ohh...and i thought its for security reasons tahks Link to comment https://forums.phpfreaks.com/topic/174343-upload-file/#findComment-919022 Share on other sites More sharing options...
backie Posted September 15, 2009 Share Posted September 15, 2009 There is also a security reason aswell. If you allow people to upload files with names they wish they maybe able to overwrite previous files. (Filename = "../../../../etc/passwd") If you allow them to upload any old type of file they could upload a copy of a php shell and then just type in the url and do whatever they want with your web page. (Depending on your set up) Personally I use "{$FileID}{$FileNameHash}.{$FileType}" as my file naming system. Link to comment https://forums.phpfreaks.com/topic/174343-upload-file/#findComment-919055 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.