Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter File Upload overwrite FALSE (default) auto-rename issue
#1

[eluser]Unknown[/eluser]
There is an error message in CodeIgniter

Quote:The file name you submitted already exists on the server

Does that make any sense? Let me explain.

There is a preference in File Uploading Class preferences called "overwrite". It can be TRUE or FALSE. The default value is FALSE. If it's TRUE, then the file will be overwritten. If it's FALSE, then a number will be appended to the filename if another with the same name exists. So, either it'll overwrite the file or it will rename the file. How is it possible to get the above error?

So, it looks like CodeIgniter is unable to rename the files properly.

I looked at my database and found how CodeIgniter has renamed the files. Though there are no other file exists with the same name, some of the filenames are appended an underscore ( _ ), but no number after that. I also found that when I tried to upload a file with file name as "myfilename.zip" several times, "myfilename_.zip", "myfilename_1.zip", "myfilename_2.zip" ... "myfilename_11.zip" found at the upload path. But "myfilename.zip" is not found there and instead of creating "myfilename_12.zip", it showed me the above error.

So, where is the issue? How to solve this?

BTW, I am using CI 2.1.2. If I will upgrade it to 2.1.3, will it fix this issue?
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

Please post your upload code. This is not a bug that I'm aware of, but I'm using v2.1.3. It looks as if there may still be a problem, however. There seems to be a limitation that a file with the same name can only be uploaded 100 times before you'll get the above error.

I would suggest taking the Upload.php file from ./system/libraries in v2.1.3, and copying it to ./application/libraries. It should be much safer than upgrading your entire system.
#3

[eluser]Unknown[/eluser]
Now I understood why I am getting the error message "The file name you submitted already exists on the server". The mechanism to check whether any file with the same name exists work for 100 files. It checks whether any file with the same name exists, if found, then it appends a number to filename and check again. This happens 100 times. If still a file with the same name found, it stops, so that the execution of the script will not take much time. So, we can say there is a limit and 100 is a good limit.

But I am still looking for the answer, why some files are appended an underscore, some with an underscore and then a number, and some with just the number. There is no consistency with the pattern to append a number to the files, if another file with the same name exists.
#4

[eluser]TheFuzzy0ne[/eluser]
It may be a bug, I'm not sure, but I can confirm it doesn't seem to be present in v2.1.3. In fact, the version I have doesn't even seem to append an underscore to the number at the end of the filename. It just seems to shove the number onto the end of the filename, just before the extension.

Have your system files been modified? Is there any reason you can't just drop in the new latest version of the upload library as I suggested?




Theme © iAndrew 2016 - Forum software by © MyBB