title: Cant Upload Photos Using Php
body: <p>I'm trying to upload a photo to mysql database using php, however I'm getting the following error:</p>
  
  <pre><code> failed to open stream: Permission denied in '/The location of my php file' on line 40.
  
   move_uploaded_file(): Unable to move '/Applications/XAMPP/xamppfiles/temp/phpgZi5gV to 'The location where the image will be stored'
  </code></pre>
  
  <p>Here is my code: </p>
  
  <pre><code>$dir = $path;
  $default = "default.png";
  
  // get Filename
  $filename = basename($filen['name']);
  $targetFilePath = $dir.$filename;
  $filetype = pathinfo($targetFilePath, PATHINFO_EXTENSION);
  
  if(!empty($filename)) {
      //allowed file formats
  
      $allowedFormats = array("jpg", "png", "jpeg", "gif", "pdf");
  
      if(in_array($filetype, $allowedFormats)) {
          if(move_uploaded_file($filen['tmp_name'], $targetFilePath)) {
              return $targetFilePath;
          }
      }
  </code></pre>