File upload is overwriting files with same filename

Hello Everyone,

I’m developing a simple document management system (document path saved, no BLOB) and I am having the problem that when I’m uploading documents that are uploaded earlier with the same filename, the file gets overwritten.
I would like to know if somebody knows a way to prevent this by changing the filename while the upload is in progress or a solution where an error is showing that there’s already a file with that name.
I don’t want to use the workaround of using different subdirectories to place the files.

I’m curious if somebody had this problem before and fixed this.

Regards!

If you copy files on your pc into the same directory with the same name they are going to overwritten too. So you need to adjust the folder name to upload to. There’s a property for that. You can use a variable if you need to create this directory dynamic.

Hallo Landgenoot,

Dank voor je reactie.

Thanks for your reply.
As stated above I don’t want to use dynamic directorys.
From my point of view this a workaround.
It would be nice to convert the name of the file before uploading.

Regards!

I’m really astonished that SC overwrites existing files without warning. If several employees are working on the same database and grid and uploading files, they cannot know wether there is already an existing file on the server…
Suggestion : SC allows in onbeforeinsert event to change the filename so the developer has control over it.
All other thinks are not practical and not useful.

Regards
Uwe Pfeiffer

I agree on the enhancement request to allow an event to change filenames. I would like to add a sequencenumber to the filename. I too have a dms in my systems, but I create subdirectories by personelnumber and date. It’s not ideal, but so far it suits my needs.

In scriptcase v6 I dug into the generated code whcih ends in …_apl.php
I put an event on nnBeforeInsert:
if (file_exists($_SESSION[‘scriptcase’][‘grid_fileupload’][‘glo_nm_path_doc’].[sc_upload_folder].{FILENAME})){
sc_error_message(‘This upload already exists:’ . {FILENAME} . "
");
};

My application is named grid_fileupload. My upload subfolder is [sc_upload_folder].
So you can do the same, check out the generated code and you should see similar statements $_SESSION[‘scriptcase’][‘grid_fileupload’][‘glo_nm_path_doc’]
this is (in V6) the path you can use to find the file.
I did disable reuploading an upload file tho. So in my case one can insert a new file (multiple ones if needed) and delete uploaded files, but NOT replace existing ones…

I hope this works in V7 similarly (havent upgraded yet…)

What about activating the ATTRIBUTE (Increment file) -> “Increment file if it already exists in the folder.”