Uploaded files are not saved from deletion and not unique

Please report bugs and any annoyances here. Kindly include all possible details: steps to reproduce, expected result, actual result, screenshots, ... etc.
Post Reply
User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Uploaded files are not saved from deletion and not unique

Post by onoehring » 2019-11-20 15:04

Hi,

AG 5.81.

Setting:
Table with FILE field:
- do not rename files
- delete from server when record removed
- Display link as field contents

To reproduce:
1. Upload file with name "something.pdf" and save.
2. Then add a new record (file). Upload the same file "something.pdf" and save.
3. You now have two entries in your table with exactly the same entry in the FILE field. - So far, so good.

1st problem
Now check the actual folder /images on your server: You will notice only ONE file. This IS a problem, as the 2nd file might actually NOT be the same as the first.

2nd problem
When you now delete ONE entry from your table (in the generated AG application) the other record will remain there (ok).
Now check the folder /images on your server again: You will notice the file is gone. It has been deleted. The effect is, that the remaining record does not have some file anymore.

Simple suggested solution (for AG developers)
a) always save files with hashed names (SHA256, not MD5 to minimize collisions).
b) as AG is using several internal tables already, why not introduce another. Fields:
- ID
- hash of "real name + unixtimestamp" (timestamp to minimize collisions)
- real name

Now AG should return this ID to the usertable .... The user can then also choose if he would like to see the real name ;-)

Well, sort of some suggestion, but the problem is serious I think.

Olaf

Olaf

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Uploaded files are not saved from deletion and not unique

Post by jsetzer » 2019-11-20 15:49

Hi Olaf,
that is exactly the reason why there is the

[ ] do not rename files

...option.

Just remove the checkbox and filenames should be unique.

Never had problems with this before. Many web apps do rename uploaded files automatically for uniqueness.

Best,
Jan
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Uploaded files are not saved from deletion and not unique

Post by onoehring » 2019-11-20 16:58

Hi Jan,

I When I posted I was thinking of people not having the knowledge to see the problems and relying too much on AG.

The problem widens, when you want to keep the names of the original files (helpful for the end user as it allows to search for contents of the filename). I did not find a solution to grab the name of the original file within AG. Do you know of any simple built-in-function? In your posting here viewtopic.php?f=4&t=2929&sid=937271b2f1 ... f6f8#p9540 you have a column with the original filename, so instead of coding this by hand it would certainly be nice to have a simple function. I tried the $data array with the fieldname, but this returns the already crypted filename only.

Olaf

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Uploaded files are not saved from deletion and not unique

Post by jsetzer » 2019-11-20 17:54

Hi Olaf,

if you need the file's original filename, you should have a look at PHP's $_FILES array.

If there is need for some custom filename-changing, you can have a closer look at the PrepareUploadedFile function in incCommon.php.

You can copy that code as a base and write your own function. As you can see in the code, there is the $_FILES array in PHP which will hold the file's original filename. You can do whatever you want with that value, for example keep the original filename or add " (1)", " (2)", ... or create a unique name based on your own pattern, and then set $data["yourfieldname"] = "new_filename"; or update the value using the sql("...", $eo) command afterwards.

For example in a project with thousands of images we were afraid, indexing, listing and image-loading could become too slow after couple of months. So we decided to automatically create subdirectories per table and sub-subdirectories per record id and then move the uploaded files there. For example /images/TABLENAME1/123/... and /images/TABLENAME1/124/... and /images/TABLENAME2/1/... and so on.

Best,
Jan


PS: Links on file-uploading
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Uploaded files are not saved from deletion and not unique

Post by onoehring » 2019-11-21 04:15

Hi Jan,

thanks for the hint to PHP's $_FILES array. This will make things probably a lot easier (than I tried to to until now ;-) )

Olaf

Post Reply