File Uploads - Duplicate File Names & Removing Files Physically

Hi,

I noticed some interesting issues with the current Document/Image uploads. I am not sure these are actual bugs or a well thought out feature that I am overlooking.

Files with Same Name

I noticed when I create two records and attach the same file for both records, Scriptcase simply replaces the existing file. Scriptcase should keep both files on the server and rename the files if needed.

Record is Deleted but Not Files

I also noticed when I click on “Delete this record” next to the attachment on a Form. It does remove the reference from the database but the File still physically exists on the server. So, the server ends up taking up unnecessary disk space. I thought about using the onAfterUpdate event but the problem is by that time the record is already updated and I cannot retrieve the file name.

I am on Scriptcase 7.00.0018.

Ad1: it depends. If you do it on your local engine, it gets overwritten too. If you have uploaded documents from different users, you need to create subfolders to get things right. Imho there’s an event missing to be used to rename the file by coding. Then everyone can change behaviour to their needs. In my opinion the current situation is too static. After all the file gets uploaded into tempspace and then moved.
Ad2: I agree, but on the other hand it conflics with your fist ad :wink: Realy, it depends on the situation. If I would need to be able to have an audit trail I realy didn’t want the file to be removed. One of our developers has created some custom code to get the files removed, but in fact this is the same issue. It should be configurable or related to a (currently missing) event.

The upload has had many issues and it’s still not mature enough. We use it extensively but by adding custom code and setting the properties in production preventing it to be overwritten. It should not have to be.

for first issue what I have is a table called documents with id as primary key; in my document setting I use /{id} as subfolder; this always makes the file unique even with same name

raj

Hello,

For the first situation you will have to create a routine to rename your files names (it can be just as find1001 suggested), or you could rename the file name… etc.

The second is just as aducom said. You might not want to enable your user to delete a file from your server (a badly intentioned user for instance). You will have to create a routine to delete those files also if you do not mind users deleting your files.

regards,
Bernhard Bernsmann

Hi,

I’m from Chile , jejeje mejor en espa?ol
Es muy muy simple, aunque me costo un poco de tiempo.
La clave es esta linea

$this->Ini->root . $this->Ini->path_imagens

se usa asi:

$dir_img = $this->Ini->root . $this->Ini->path_imagens . “” . nombre_carpeta . “/” . nombre_foto ";

por lo tanto en $dir_img, esta la direccion de tu archivo.

Ahora usando codigo php normal, puedes borrar archivos o copiar con otro nombre.

Yo lo uso en el evento onBeforeUpdate, pero seg?n la necesidad puedes hacer mucho.
Por ejemplo si borran las imagenes, en un onLoad u onRefresh, realizas una busqueda en la
base de datos de todas las imagenes que existen, realizas una busqueda en los archivos
y usando $dir_img vas eliminando cuando corresponda.

Saludos,
PD: es mas simple de lo que parece.

You all are use very long process please go shortcut and use Duplicate File Deleter it can delete all duplicate files eg.-music,EXE. and same name files etc.
I had a similar problem many times. The duplicate files are such that they my hard drives used to end up with bad sectors. Also,
there was always a shortage of free space. I regularly use “Duplicate Files Deleter” when i feel that my computer is lagging. You should try it too