title: Unable to write in the Directory - Digital Ocean
body: <p>I am trying to upload an image with post request and move it to a directory. I tried..</p>
  <pre><code>$file = $request-&gt;file('file');
  $extension = strtolower($file-&gt;getClientOriginalExtension());
  
  $finfo = finfo_open(FILEINFO_MIME_TYPE);
      
  $generatedName = sha1(time().time());
  $directory = '../public/uploads/imgs/'; // works
  $fileName =  $generatedName . &quot;.&quot; . $extension; // works
  
  // 1
  $file-&gt;move($directory, $fileName);
  // 2
  $file-&gt;move(base_path().$directory, $fileName);
  </code></pre>
  <p>At this point, I am receiving error:</p>
  <blockquote>
  <p>1 Unable to write in the &quot;../public/uploads/imgs&quot; directory</p>
  <p>2 Unable to write in the &quot;var/www/laravel/public/uploads/imgs&quot; directory</p>
  </blockquote>
  <hr />
  <p>I thought it was caused by permissions but didn't help either.. I tried</p>
  <pre><code>sudo chmod 770 /var/www/laravel/public/uploads (also /imgs/
  and
  sudo chmod -R 775 /var/www/laravel/public/uploads 
  </code></pre>
  <p>I also found something else to try but couldn't figure out what to write in username bit:</p>
  <pre><code>sudo chown username:www-data /var/www/laravel/public/uploads/
  </code></pre>
  <hr />
  <p>I am using NGINX on Digital Ocean</p>