quadrant
Ecommerce Template Guru
United Kingdom
1110 Posts Pre-sales questions only (More Details...)
|
Posted - 09/21/2023 : 11:52:13
Hi,
We are currently running PHP v7.6.2 and have setup the built in Order Image Uploader to replace an older one we have had for years. It's really easy to configure and find it particularly nice you can access the images directly from the orders admin page.
One issue we are having however is with the file renaming upon upload as they are being renamed with the order ID which is where the problem is.
I think adding the order ID is great but I am hoping the original file name can be retained and just appended with the order ID instead of completely renaming it.
The issue we are finding is that customers often name their files in relation to the products they are for.
For example: product_1_front.pdf product_1_back.pdf product_2_front.pdf product_2_back.pdf
If the order ID is 1234 these then get renamed to the following: i01234_00.pdf i01234_01.pdf i01234_02.pdf i01234_03.pdf
This then means we have to contact the customer and ask which files are for what as it's not always obvious leading to frustration as they normally say something like 'we named the files for you'.
Is there a way to keep the original file name and perhaps just append it with the order ID so the above examples become: i01234_product_1_front_00.pdf i01234_product_1_back_00.pdf i01234_product_2_front_00.pdf i01234_product_2_back_00.pdf
Obviously it's a good idea to add _00, _01, _02 to the end as we have also had customers dragging the same file more than once as they don't realise it automatically uploads so it's a good way of handling matching file names.
So if they uploaded the same file twice we would get: i01234_product_1_front_00.pdf i01234_product_1_front_01.pdf
Hopefully a solution can be found for this.
Regards, David
|
Vince
Administrator
42960 Posts |
Posted - 09/23/2023 : 07:41:21
|
quadrant
Ecommerce Template Guru
United Kingdom
1110 Posts Pre-sales questions only (More Details...)
|
Posted - 09/24/2023 : 03:09:38
Hi Vince,
That makes sense about sanitizing the name.
I have done a bit a digging around online and it seems there are a few possible solutions that may work allowing the original file name to be kept intact (minus any illegal characters) and then maybe add the order ID also as having that is really helpful.
[url]https://stackoverflow.com/questions/2021624/string-sanitizer-for-filename[/url]
[url]https://www.codexworld.com/how-to/clean-up-filename-string-to-make-url-and-filename-safe-using-php/[/url]
I have had a go at this but couldn't get things working when I tried adding to ajaxservice.php Maybe I am looking in the wrong place.
Please could you let me know if any of the above offers any possibilities?
Regards, David
|
Vince
Administrator
42960 Posts |
Posted - 09/25/2023 : 04:13:43
Hi David I think I have a solution to this that would work and it is to allow a parameter $GLOBALS['uploadfilenametemplate'] where you can use modifiers for the order id, image number and original filename. The original would be something like this... $GLOBALS['uploadfilenametemplate']='i%ordid%_%imagenum%'; But if you wanted to use the original filename you could use say... $GLOBALS['uploadfilenametemplate']='i%filename%_%imagenum%'; Or even in conjunction with the order id... $GLOBALS['uploadfilenametemplate']='i%ordid%_%filename%_%imagenum%'; I'm still testing and I've got to get the ASP version done, but I'll let you know when it is available. Vince Click Here for Shopping Cart SoftwareClick Here to sign up for our newsletterClick Here for the latest updater
|
quadrant
Ecommerce Template Guru
United Kingdom
1110 Posts Pre-sales questions only (More Details...)
|
Posted - 09/25/2023 : 04:39:31
Hi Vince,
That's great news thank you. Having a parameter to make the file name flexible sounds like an excellent idea.
Regards, David
|
dbdave
ECT Moderator
USA
10498 Posts |
Posted - 09/25/2023 : 08:07:57
Thanks Vince, I can use this too - People do strange things when uploading files. The filename is sometimes needed when they omit comments.
David
|
Vince
Administrator
42960 Posts |
Posted - 09/26/2023 : 05:23:49
|
quadrant
Ecommerce Template Guru
United Kingdom
1110 Posts Pre-sales questions only (More Details...)
|
Posted - 09/26/2023 : 07:17:48
Hi Vince,
Thank you for the changes. That should reduce the amount of times we have to contact customers.
Just to clarify do we still need to use $GLOBALS['uploadfilenametemplate']=
I am guessing by prefix you are referring to the i that is currently used. Is the prefix used as some sort if identifier elsewhere so must be used but can be what we want?
Also is the _%imagenum% automatically added when a name conflict is encountered meaning we do not need to add to global setting for it to work or is it safer to add to parameter?
Regards, David
|
Vince
Administrator
42960 Posts |
Posted - 09/26/2023 : 07:32:29
Hi David quote: Just to clarify do we still need to use $GLOBALS['uploadfilenametemplate']=
Yes, you still need to use that parameter. For instance... $GLOBALS['uploadfilenametemplate']='prefix%ordid%_%filename%'; quote: I am guessing by prefix you are referring to the i that is currently used.
That's right, but it's optional. quote: Also is the _%imagenum% automatically added when a name conflict is encountered meaning we do not need to add to global setting for it to work or is it safer to add to parameter?
It's automatically added but would only be added to the name in the case of conflict. So if you want all your images to contain the image number, then just add it. Vince Click Here for Shopping Cart SoftwareClick Here to sign up for our newsletterClick Here for the latest updater
|
quadrant
Ecommerce Template Guru
United Kingdom
1110 Posts Pre-sales questions only (More Details...)
|
Posted - 09/28/2023 : 08:15:08
Hi Vince,
Upgraded to v7.7.1 and the uploaded file name is much better thanks.
Regards, David
|
|
|