title: Warning: move_uploaded_file(); failed to open stream
body: <p>I'm trying to upload image using <code>move_uploaded_file();</code></p>
  
  <pre><code>$target_dir = "product_images/";
  $target_file = $target_dir . basename($_FILES["product_image"]["name"]);
  if (move_uploaded_file($_FILES["product_image"]["tmp_name"], $target_file)) { // Line 92
      echo "&lt;script&gt;alert('The file " . basename( $_FILES["product_image"]["name"]) . " has been uploaded.')&lt;/script&gt;";
  } else {
      echo "&lt;script&gt;alert('Sorry, there was an error uploading your file.')&lt;/script&gt;";
      die();
  }
  </code></pre>
  
  <p>So when I try to execute this code I'm getting this error:</p>
  
  <pre class="lang-none prettyprint-override"><code>Warning: move_uploaded_file(product_images/img_forest.jpg): failed to open stream: Permission denied in /opt/lampp/htdocs/suvenirshop/admin_area/insert_product.php on line 92
  
  Warning: move_uploaded_file(): Unable to move '/opt/lampp/temp/phpZEJdEV' to 'product_images/img_forest.jpg' in /opt/lampp/htdocs/suvenirshop/admin_area/insert_product.php on line 92
  </code></pre>
  
  <p>I'm using xampp on linux, I also tried this code on windows pc and mac where I get the same error.
  I have to mention that I have folder product_images in folder where I stored insert_product.php which execute this code.</p>