简体   繁体   中英

“Permission denied” when uploading files

I'm trying to implement a simple script for file uploading. Here's the code:

<?php
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = strtolower(end(explode(".", $_FILES["fotocarnet"]["name"])));
if ((($_FILES["fotocarnet"]["type"] == "image/gif")
|| ($_FILES["fotocarnet"]["type"] == "image/jpeg")
|| ($_FILES["fotocarnet"]["type"] == "image/png")
|| ($_FILES["fotocarnet"]["type"] == "image/pjpeg"))
&& ($_FILES["fotocarnet"]["size"] < 20000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["fotocarnet"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["fotocarnet"]["error"] . "<br>";
    }
  else
    {
    echo "Upload: " . $_FILES["fotocarnet"]["name"] . "<br>";
    echo "Type: " . $_FILES["fotocarnet"]["type"] . "<br>";
    echo "Size: " . ($_FILES["fotocarnet"]["size"] / 1024) . " kB<br>";
    echo "Temp file: " . $_FILES["fotocarnet"]["tmp_name"] . "<br>";

    if (file_exists("nada/" . $_FILES["fotocarnet"]["name"]))
      {
      echo $_FILES["fotocarnet"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["fotocarnet"]["tmp_name"],
      'nada/' . $_FILES["fotocarnet"]["name"]);
      echo "Stored in: " . "nada/" . $_FILES["fotocarnet"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file: ".$extension;
  }
?>

Here's the output

Upload: MARTÍNEZGARCÍAGIANCKO.JPG
Type: image/jpeg
Size: 3.6513671875 kB
Temp file: C:\Windows\Temp\phpE21C.tmp

Warning: : failed to open stream: Permission denied in C:\inetpub\wwwroot\Italia\IngSubirFotoCarnetIns_Italia.php on line 29

Warning: move_uploaded_file(): in C:\inetpub\wwwroot\Italia\IngSubirFotoCarnetIns_Italia.php on line 29
Stored in: nada/MARTÍNEZGARCÍAGIANCKO.JPG

And in php.ini I have this:

upload_tmp_dir=C:\inetpub\wwwroot\upload

The catch: I've already set the permissions to C:\\Windows\\Temp\\ , to C:\\inetpub\\wwwroot\\upload and to C:\\inetpub\\wwwroot\\Italia\\nada . Not only that but I already tried with ini_set() . Worst, I even upgraded PHP to 5.4 and it's still not working (and in every case I get the exact same error with the exact same upload folder, in Windows\\Temp ).

What am I doing wrong here?

答案很简单:我必须设置对USERS完全权限。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM