Jump to content

Custom Upload Names


adrian

Recommended Posts

Just now, PWaddict said:

It seems that only if the value is empty the cleanBasename will properly work in Windows.

@matjazp - can you confirm this on your setup?

If this is reproducible it sounds like we need to file an issue as it's not related to this module.

Link to comment
Share on other sites

I was suspecting locale problems from the very beginning, that's why I asked to dump basename() and pathinfo() calls since they are both locale aware. Just to test again, could you @PWaddict try this:

d(basename("ä"));

with and without translated "C" in LanguageSupportModule? Though I'm getting the correct results regardless of "C" value.

That's why we have a check that is performed on every login (and some changes are introduced recently to better clarify the issue here)! Do you get a warning message when you log in, something like "Note: your current server locale setting isn’t working as expected with the UTF-8 charset and may cause minor issues. Your current locale setting is “en_US.UTF-8”. Please translate the “C” locale setting for each language to the compatible locale in  ... " ? if not, then why you translated the "C" in the first place and also translated to the nonexisting locale? There is no need to translate "C" string on windows (from my experience). Windows don't have "en_US.UTF-8" locale, that's why PW suggest "en-US". The list of supported locales on windows: https://msdn.microsoft.com/library/cc233982.aspx , see the language tag column.

As for getting mixed results: the locale information is maintained per process, not per thread. If you are running PHP on a multithreaded server API like IIS, HHVM or Apache on Windows, you may experience sudden changes in locale settings while a script is running, though the script itself never called setlocale(). This happens due to other scripts running in different threads of the same process at the same time, changing the process-wide locale using setlocale().

Glad you solved the problem ? 

  • Like 2
Link to comment
Share on other sites

Wow @matjazp - thanks for a brilliantly detailed answer - much appreciated. i must admit I am not very au fait with this locale stuff.

I guess I am a little curious why PW's cleanBasename() has issues with this and yet $sanitizer->filename() and $sanitizer->pagName() with Sanitizer::translate do not. I guess I feel like they should all handle these translations the same way and so should all be subject to the same "issue".

 

Link to comment
Share on other sites

2 minutes ago, adrian said:

I guess I am a little curious why PW's cleanBasename() has issues with this and yet $sanitizer->filename() and $sanitizer->pagName() with Sanitizer::translate do not. I guess I feel like they should all handle these translations the same way and so should all be subject to the same "issue".

Yep. But it's hard to work on things that are working and you are trying to make them not working just do debug them ? 

Link to comment
Share on other sites

24 minutes ago, matjazp said:

Just to test again, could you @PWaddict try this:

d(basename("ä"));

with and without translated "C" in LanguageSupportModule? Though I'm getting the correct results regardless of "C" value.

I'm getting "ä" (2) on both.

I translated the "C" string for the languages long time ago for 2 reasons: 

- Displaying on frontend the months in date format for each locale.
- Adding months on page names via ProcessSetupPageName module.

For the main language actually I had "en_US.utf8, English_United States" and for the alternate languages "es_ES.utf8, Spanish_Spain.1252" & "de_DE.utf8, German_Germany.1252". On each locale the first string is for Linux and the 2nd for Windows. I left both there as the "C" notes saying: Specify CSV string of locales to try multiple locales in order. That way I don't need to switch locales when for example I migrate the database from the live server on localhost for developing, testing etc.

It seems that I don't need the "en_US.utf8, English_United States" for the main language so I left it empty but what if the main language wasn't English? How could I do the above if translating the "C" string on main language is causing problems on cleanBasename?

Link to comment
Share on other sites

I cant't help any more since I'm going to a vacation for a few days. It would be helpful if you find the reason for all this. Will it help if you use just "en-US" for the windows locale? Or try this script: https://www.zen-cart.com/attachment.php?s=ecb022422821941d39f3bff5511c3ecb&attachmentid=16404&d=1465221878

  • Like 1
Link to comment
Share on other sites

5 hours ago, matjazp said:

I cant't help any more since I'm going to a vacation for a few days. It would be helpful if you find the reason for all this. Will it help if you use just "en-US" for the windows locale? Or try this script: https://www.zen-cart.com/attachment.php?s=ecb022422821941d39f3bff5511c3ecb&attachmentid=16404&d=1465221878

It doesn't matter if I enter a valid or a non-valid locale on "C" string. The cleanBasename will always be broken if "C" isn't empty. I tried this on the fresh PW installation and the same problem happens so I will post an issue on GitHub.

Thanks for the help @adrian & @matjazp and wish you Merry Christmas!

  • Like 1
Link to comment
Share on other sites

Having a dot on the text field it doesn't process the filename properly after that dot. It happens on both Windows & Linux.

Text Field value: T. Test ä
Filename: t._test____1545258287.jpg

Text Field value: Test ä T.
Filename: test_a_t._1545258287.jpg

Note: That issue doesn't happen on 1.2.2.

  • Like 1
Link to comment
Share on other sites

On 12/21/2018 at 4:27 PM, PWaddict said:

It doesn't matter if I enter a valid or a non-valid locale on "C" string. The cleanBasename will always be broken if "C" isn't empty. I tried this on the fresh PW installation and the same problem happens so I will post an issue on GitHub

I'm still not satisfied as I can't replicate this. I would like to perform some more tests, but don't want to pollute this thread, so if you are interested in narrowing down this issue, please PM me, @PWaddict 

  • Like 1
Link to comment
Share on other sites

Thanks for the feedback. I posted suggested solution on the github. 

On 12/21/2018 at 6:26 AM, adrian said:

I guess I am a little curious why PW's cleanBasename() has issues with this and yet $sanitizer->filename() and $sanitizer->pagName() with Sanitizer::translate do not.

That's because $sanitizer->(file)name() checks for multibyte support and uses mb_strtolower().

  • Like 1
Link to comment
Share on other sites

2 hours ago, matjazp said:

@PWaddict could you please modify $basename = strtolower($basename); to $basename = mb_strtolower($basename); in cleanBasename method in /wire/core/Pagefiles.php (line 568).

Nice catch!

It's interesting because many of the $sanitizer methods make use of the internal nameFilter() method which uses mb_strtolower.

If you actually follow the cleanBasename method it goes through $sanitizer filename(), which uses name(), which uses nameFilter() which leads me to believe that it might actually be possible to just remove that that: $basename = strtolower($basename); line from the cleanBasename() method completely. I just tested this and it's actually pretty close - there are a couple of problems - one is the regex on #578 needs A-Z added to it. The other is that beautify doesn't get passed through to nameFilter() which is a condition for mb_strtolower() being called.

Anyway, that was just an interesting excursion into what is actually going on and where ?

  • Like 1
Link to comment
Share on other sites

  • 5 months later...
8 hours ago, PWaddict said:

@adrian I found a small bug. Using slashes for example on the title field the image doesn't rename properly. For example on title field I have: Poster/Flyer and the image renamed to flyer.jpg where it should be poster_flyer.jpg.

Should be fixed now!

  • Thanks 1
Link to comment
Share on other sites

  • 3 months later...

Hello @adrian

Today I noticed a very strange behaviour with the module. If I upload an image on the Image or CroppableImage3 field and then add a new repeater item on a repeater field and publish / save the page, the image doesn't display on front-end. The image and its variations are visible on back-end and on the related folder in assets.

If I first add a new repeater item on a repeater field and then upload an image on the Image or CroppableImage3 field then there is NO problem. WTF?

I verified that this is caused by the module cause when I temporarily disable the rule there was NO problem. My rule is: {$page->title}_{$file->mtime} with Rename on Save checked.

I'm using PW 3.0.135.

Link to comment
Share on other sites

@PWaddict - I feel like I have replicated your described workflow and I am not seeing any problems so I will need more troubleshooting from you. 

Why doesn't the image display on the frontend - is the code trying to display an image with a non-existant path?
What code are you using to display the image?
What are the image settings - anything related to the max files or overwrite settings that are relevant?

Anything you can do to narrow it down further would be very helpful.

Link to comment
Share on other sites

The structure on my template is in this order:

various fields
Image field
Repeater field
Repeater field
various fields

The image doesn't display on frontend because it seems that it doesn't get saved in database??? I'm checking if the image exists like this: if($page->image) etc. There is nothing wrong in the code on template cause if I save the page AGAIN then this time the image is properly getting saved and displayed on frontend.

Image Maximum files allowed: 1
Formatted value: Automatic

EDIT: It's a multi-language site.

Link to comment
Share on other sites

I am testing on a multi-language site and just changed to max files 1 and it's still all working as expected. Sorry, I am not sure what else to look at right now. I am curious what Tracy's PageFiles panel reports after the initial saving of the page.

Link to comment
Share on other sites

Ok, I think I have narrowed it down - if you don't have "overwrite" checked and you use $file->mtime it doesn't know how to name the file at the correct point it needs to. It's also necessary to have "Rename on Save" checked to have this problem.

Let me see if I can fix.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...