JamesHeinrich / phpThumb

phpThumb() - The PHP thumbnail generator
Other
315 stars 98 forks source link

open_basedir on Windows preventing from caching the images #164

Closed alpenbytes closed 3 years ago

alpenbytes commented 3 years ago

Summary

So a set open_basedir in PHP for Windows which points to the application path of the website prevents phpthumb from creating the processed images in the cache directory.

Current behavior

My open_basedir in Plesk is automatically set to this C:/Inetpub/vhosts/domain.de\;C:\Windows\Temp\ The thing is now, with the delimiters ":" and ";" the whole thing in phpthumb.functions::EnsureDirectoryExists() is splitted into: Array ( [0] => C [1] => /Inetpub/vhosts/domain.de\ [2] => C [3] => \Windows\Temp\ ) The problem is the Unix delimiter ":" in open_basedir: It is used on Windows for the volume disk name so the above thing is produced. phpthumb.functions::EnsureDirectoryExists() now iterates over "C" to check if "C:\" is writable. Obviously this is not the case as it is outside open_basedir and the current webspace user does not have permission to do so. Only the first array value is used by the script to check if the directory is writable in this case.

Please note that XAMPP for Windows does not set open_basedir, so the phpThumb check is successful as C: is writable. Keep that in mind when testing for this issue. I'm developing on XAMPP locally and only discovered that out after deploying to my Windows Server with Plesk.

Expected behavior

would be this output after splitting open_basedir: Array ( [1] => C:\Inetpub\vhosts\domain.de\ [3] => C:\Windows\Temp\ ) C:\Inetpub\vhosts\domain.de is writable with the current Plesk webspace user and the check is truthy and the script continues as expected with the creation of the cache image.

Am I doing something wrong here with the open_basedir? Especially since this issue must be around since 2007 (perhaps not so many PHP for Windows users).

If not, I'm ready to make a PR with the fixed open_basedir split (I already fixed it in my code). And also another fix when phpThumb is used with Plesk for Windows Server, as Plesk populates the automatically created open_basedir path with forward-slashes instead of backslashes which also prevents the is_writable check in the said function.

JamesHeinrich commented 3 years ago

In principle I like your proposed changes, but I would prefer to lay it out a little differently: https://github.com/JamesHeinrich/phpThumb/commit/2e4249d47a53ff076229cd690798fbed66e5635d I separated out the Windows vs non-Windows sections for greater clarity. I also made it explicit that Windows pathnames are matched case-insensitive, unix ones are case-sensitive so it's important that case-insensitivity is applied only to Windows.

Would you be able to test this variation of that code block to confirm it works in your configuration, please?

alpenbytes commented 3 years ago

I like your approach too and it works on my local Windows machine as well as on my Plesk Windows Server. Thank you. I'll close this issue and PR as it is fixed.