title: failed to open stream: Permission denied [upload photo]
body: <p>Currently using macbook + apache + phpmyadmin + php + xampp. (running on localhost)</p>
  
  <p>I'm trying to upload a photo into one of the folders through php but i am receiving this warning. </p>
  
  <p>Is there any solution to this issue through macbook file setting? </p>
  
  <blockquote>
    <p>Warning: file_put_contents(image/img_post720151014060113101414.jpg): failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/CS2102/signup.php on line 32
    couldn't execute query.</p>
  </blockquote>
  
  <p>Codes:</p>
  
  <blockquote>
    <p>
  </blockquote>
  
  <pre><code>include("db.php");
  
  $userEmail = $_POST["userEmail"];
  $firstName= $_POST["firstName"];
  $lastName = $_POST["lastName"];
  $userPassword = $_POST["userPassword"];
  $nationality = $_POST["nationality"];
  $birthday = $_POST["birthday"];
  $gender = $_POST["gender"];
  
  // prepare the image for insertion
  $imgData =addslashes (file_get_contents($_FILES['test']['tmp_name']));
  $bio = $_POST["bio"];
  
  $filename = "img_post" . rand(1, 9) . date("YmdHis") . rand(25, 125) . rand(256, 850);
  $allowed  = array(
      "image/jpeg",
      "image/pjpeg",
      "image/jpg",
      "image/png",
      "image/JPEG",
      "image/bmp",
      "image/PNG"
  );
  
  $result= UploadFile("test", $allowed, 10000000);
              if ($result[0] == 0) {
                  // Put Photo uploaded into sever folder
                  file_put_contents("image/" . $filename . ".jpg", $result[2]);
                  $date  = (String) date("Y-M-d-H:i:s");
  
                  // Query String
                  $query = "INSERT INTO `user` (`userEmail`,`password`, `firstName`,  `lastName`,  `nationality`,`birthday`,`gender`,`picSrc`,`bio`) VALUES ('$userEmail','$password','$firstName','$lastName','$nationality','$birthday','$gender', '{$imgData}', '$bio')";  
                  // Execute Query
                  mysqli_query($mysqli,$query) or die("couldn't execute query.");
                  echo '&lt;script language="javascript"&gt;';
                  echo 'alert("Photo Uploaded");';
                  echo 'window.location.href="loginreg.php";';
              } else {
                  if ($result[0] == "-1")
                      echo "wrong";
                  if ($result[0] == "-2")
                      echo "wrong file type";
                  if ($result[0] == "-3")
                      echo "MAximum length exceeded";
                  if ($result[0] &gt; 0)
                      echo "Error due to $result";
                  echo $result[0];
                  echo $result;
                  echo "&lt;br/&gt;File Upload Error!";
  
              }
  
  
  function UploadFile($name, $filetype, $maxlen)
  {
      if (!isset($_FILES[$name]['name']))
          return array(
              -1,
              NULL,
              NULL
          );
      if (!isset($_FILES[$name]['type'], $filetype))
          return array(
              -2,
              NULL,
              NULL
          );
      if ($_FILES[$name]['size'] &gt; $maxlen)
          return array(
              -3,
              NULL,
              NULL
          );
      if ($_FILES[$name]['error'] &gt; 0)
          return array(
              $_FILES[$name]['error'],
              NULL,
              NULL
          );
  
      $temp = file_get_contents($_FILES[$name]['tmp_name']);
      return array(
          0,
          $_FILES[$name]['type'],
          $temp
      );
  }
  
  
  ?&gt;
  </code></pre>