title: Upload an image and create its thumbnail Laravel 5.2
body: <p>So yesterday I tried to make an <a href="https://stackoverflow.com/questions/41671373/upload-images-and-showing-them-in-a-view-laravel-5-2">upload file function</a> , for when user makes his products, he can also upload a picture too. </p>
  
  <p>But the picture was too big when I was iterating through the items, so I decided to use intervention package to resize the picture and also create a thumbnail picture.</p>
  
  <p>I made the function but its partially working.</p>
  
  <pre><code>if($file = $request-&gt;hasFile('image')) {
          $file = $request-&gt;file('image');
          $extension = $file-&gt;getClientOriginalName();
          $username = Auth::user()-&gt;username;
          $destinationPath = public_path('/uploads/products/' . $username);
          $thumb = Image::make($file-&gt;getRealPath())-&gt;resize(100, 100, function ($constraint) {
              $constraint-&gt;aspectRatio(); //maintain image ratio
          });
          $thumb-&gt;save($destinationPath.'/thumb_'.$extension);
          $destinationPath = public_path('/uploads/products/' . $username);
          $file-&gt;move($destinationPath, $extension);
          $product['imagePath'] = '/uploads/products/'. $username . '/' . $extension;
          $product['thumbnail'] = '/uploads/products/'. $username . '/thumb_' . $extension;
      }
  </code></pre>
  
  <p>I made it so, different user will create a different file in <code>/uploads/products</code>.</p>
  
  <p>Also I upload the original picture and the resized so the I should have like:
  <code>picture.jpg</code> and <code>thumb_picture.jpg</code>.</p>
  
  <p>When the custom file is not created (from the name of the user) I get this error:</p>
  
  <blockquote>
    <p>Can't write image data to path
    (C:\xampp\htdocs\shop\public/uploads/products/book/thumb_Jellyfish.jpg)</p>
  </blockquote>
  
  <p>When I comment 6,7,8 lines, the function works but it uploads only the original picture as it supposed to. If I remove the comment, the thumbnail works too!</p>
  
  <p>So I guess, after the custom folder has been created, the whole function works fine, but before it has a writable problem. </p>
  
  <p>Any ideas? Everything will be appreciated!</p>