1
<?php

if (isset($_FILES['datei']))
{
move_uploaded_file($_FILES['datei']['tmp_name'], 'upload/'.$_FILES['datei']['name']);

echo "Filee successfully uploaded.";

chmod($_FILES["datei"]["name"], 777);

echo "<p> Chmod successfully set!<br>";
} 

?>

上传有效,但未设置 chmod。任何人都可以帮忙检查代码吗?

4

4 回答 4

4

You need to have an absolute path to your file. For example:

chmod("/var/www/files/uploads/" . $_FILES["datei"]["name"] . ".jpg", 0777)

Make sure the file location actually exists. The cheap and dirty way to do this:

if(!file_exists("/var/www/files/uploads/" . $_FILES["datei"]["name"] . ".jpg")) {
  die("File not found with path: /var/www/files/uploads/" . $_FILES["datei"]["name"] . ".jpg");
}

EDIT: also, on Aquillo answer, it should be 0777.

于 2013-04-23T19:22:17.397 回答
1

You move the file to 'upload/'.$_FILES['datei']['name'] but chmod $_FILES['datei']['name']. Note you've been missing the `upload/'. Change the chmod to:

chmod('upload/'.$_FILES['datei']['name'], 0777);
于 2013-04-23T19:22:22.223 回答
0

您应该将 chmod 设置为

chmod($_FILES["datei"]["name"], 0777);

你可以在这里阅读更多关于它的信息。

于 2013-04-23T19:21:09.587 回答
0

您需要在模式前加上零 (0),所以

mode should be 0777
chmod($_FILES["datei"]["name"], 0777); //correct way of mode
于 2015-06-26T06:20:57.503 回答