SimplySavage
SimplySavage

Reputation: 63

PHP Considers my absolute path a relative one

Currently I have PHP 7.2 installed and I was trying to get spatie/image-optimizer to work but somehow it considers my literal paths as non existent ones. If I give it the following path:

/data/www/MY DOMAIN/images/thumbnails/700/615/detailed/1/83-221-343-V01.jpg

It will output the following:

2018/07/13 14:44:26 [error] 18931#18931: *3749 FastCGI sent in stderr:

"PHP message: PHP Fatal error: Uncaught InvalidArgumentException:

/data/www/MY DOMAIN/images/thumbnails/700/615/detailed/1/83-221-343-V01.jpg

does not exist in

/data/www/MY DOMAIN/app/addons/theme/lib/vendor/spatie/image-optimizer/src/Image.php:14

But if I check the directory I can confirm that the file is there with the correct permissions.

Any ideas?

Upvotes: 0

Views: 190

Answers (2)

delboy1978uk
delboy1978uk

Reputation: 12355

I just looked at the Image class on Github. Here's where the exception is thrown.

public function __construct(string $pathToImage)
{
    if (! file_exists($pathToImage)) {
        throw new InvalidArgumentException("`{$pathToImage}` does not exist");
    }
    $this->pathToImage = $pathToImage;
}

A good way of checking you have it properly set is to use realpath()

Realpath creates absolute paths from relative ones, returning false if the path doesn't exist.

$path = __DIR__ .'/../../something'; // (imagine __DIR__ is /some/random/path to begin with)
echo $path; // outputs /some/something

You can also check in your terminal simply by typing:

ls /path/to/image.jpg

If it lists, it does indeed exist and shouldn't throw an error.

Upvotes: 2

Goran Jurić
Goran Jurić

Reputation: 1839

Switch to the user your php is running as and try to access the file. It could be that you are missing the execute permissions on one of the folders on the way to the file.

Upvotes: 0

Related Questions