PHP-成功上传后设置chmod?

<?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>";
} 

?>

The upload works, but the chmod isn't set. Can anyone help out and check the code ?

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.

You should set the chmod as

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

You can read more about it here.

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);

you need to prefix mode with a zero (0), so

mode should be 0777
chmod($_FILES["datei"]["name"], 0777); //correct way of mode