Maxlight Maxlight - 1 month ago 5x
PHP Question

creating image inside a folder results in creating an image with name folder/image.jpg

I have this piece of code:

$file = $faker->image($dir = public_path().'/tmp', $width = 800, $height = 600, '', true);
$hash = str_random(7);
$thumbnailName = $hash . '.jpg';
$thumbnailImage = ImgResizer::make($file)->fit(180, 180);
$thumbnailImage->save( public_path() . '\\thumb\\'. $thumbnailName);
rename($file, 'public/'.$hash.'.jpg');

As you can see I am using
to populate the database. Faker supports images as well and it's getting images from I save this image directly in public folder and that works. I also create a thumbnail of the image using
and save it to public/thumb folder as you can see in the code.

When I run the db:seed, no errors were produced, it all went well. However when I looked inside thumb folder there were no files there. There were bunch of images created inside public folder but not inside thumb. I logged in the server and cd into default folder and typed ls and I got this output:

As you can see on the image there are bunch of
images there. How is this possible, they are not inside thumb folder, why is it listing them there? Did the script instead create file with filename
? How do I put them inside thumb folder? This code works on my local machine windows 10 under apache2 and php7.


Try change this:

public_path() . '\\thumb\\'. $thumbnailName

To this:


Also, create thumb directory and set correct permissions:

chmod -R 755 /public/thumb