rosell-dk / webp-express

Wordpress plugin for serving autogenerated WebP images instead of jpeg/png to browsers that supports WebP
GNU General Public License v3.0
225 stars 64 forks source link

'Path of source is not within a valid image root' on local XAMPP or: isPathWithinExistingDirPath does not respect windows path separator #557

Open dartrax opened 2 years ago

dartrax commented 2 years ago

When I try this plugin locally (xampp), I get the following error in the testing conversion window: Path of source is not within a valid image root I'm not the only one: Wordpress Plugin Support Forum

The culprit is that your isPathWithinExistingDirPath function does not respect the windows path separator. For example,

self::isPathWithinExistingDirPath(
    "C:\xampp\htdocs\wp\wp-content\plugins\webp-express/test/alphatest.png", 
    "C:\xampp\htdocs\wp/wp-content/plugins"
)

should return "true" while it actually returns "false".

I was able to fix this by adding two lines at the beginning of the isPathWithinExistingDirPath function in PathHelper.php. But there may be better ways to solve that.

$path = \str_replace('\\', '/', $path);
$dirPath = \str_replace('\\', '/', $dirPath);

Ahh, and one more thing:

You can also setup the ewww conversion method. To use it, you need to purchase an api key. They do not charge credits for webp conversions, so all you ever have to pay is the one dollar start-up fee šŸ™‚ (unless they change their pricing ā€“ I have no control over that).

They have changed there pricing, seems like they don't do it for less than $7 every month (!)... You should update the plugin description ;-)