3

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 faker to populate the database. Faker supports images as well and it's getting images from lorempixel.com. I save this image directly in public folder and that works. I also create a thumbnail of the image using InternventionImage 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 public/thumb/hashcode.jpg 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 public/thumb/hashcode.jpg? How do I put them inside thumb folder? This code works on my local machine windows 10 under apache2 and php7.

Blue
  • 22,608
  • 7
  • 62
  • 92
niko craft
  • 2,893
  • 5
  • 38
  • 67
  • 1
    The problem is that the follwoing code public_path() . '\\thumb\\'. $thumbnailName creates images in public_path() with name '\\thumb\\'. $thumbnailName. Use public_path() . '/thumb/'. $thumbnailName to save them inside thumb. – Andrej Aug 28 '16 at 13:13

1 Answers1

1

Try change this:

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

To this:

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

Also, create thumb directory and set correct permissions:

chmod -R 755 /public/thumb
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
  • I ended using public_path() . '/thumb/'. $thumbnailName as suggsted by Andrej above. However your answer also works so I'll accept it as the answer to question. – niko craft Aug 28 '16 at 16:41