Announcement

#1 2021-12-15 22:50:50

i2000
Member
2021-12-15
1

How to customize the upload directory and file renaming?

hi~

I need to upload all the files to . /uplods, instead of taking the /YYYY/MM format to create more subdirectories.

How can I customize the renaming rules when uploading files? I want to remove the date from the file name

The original style: https://img.com/_data/i/upload/2021/12/ … u_e663.jpg
I want to change it to: https://img.com/_data/i/upload/5a0f2d6d-cu_e663.jpg or https://img.com/upload/5a0f2d6d-cu_e663.jpg

Thanks

Offline

 

#2 2021-12-16 01:49:36

erAck
Only trying to help
2015-09-06
1338

Re: How to customize the upload directory and file renaming?

Take a look at admin/include/functions_upload.inc.php in function add_uploaded_file() line 197 and following, starting with the comment
// upload directory hierarchy

However, to get rid of the upload date altogether you would have to not only strip the subdirectories from $upload_dir but also substitute the $date_string in $filename_wo_ext (with what?), and then implement a mechanism to prevent filename clashes, the simple $random_string partial md5sum without the date+time and not in subdirectories will not be sufficient.

Note that path+filename are stored in the database table piwigo_images column `path`, so changing already existing path names will need adaption there as well.

Anyway, I doubt that upload function would be the only place to be adapted, there may be other places that assume the current structure, grep for upload_dir (of the $conf['upload_dir'] setting) and inspect code around, also plugins may be affected and even hardwire things. Be prepared that things may break or not work the way you'd like.

Also note that cramming all files into one directory may significantly slow down things for a huge amount of images, even worse with the thumbnail derivatives that are generated under _data/i/upload/ (however that might be affected by the change) that even multiply the amount of files.

What would that even be good for anyways? It's just the upload date+time you see.


Running Piwigo at https://erack.net/gallery/

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2022 · Contact