Issue
<?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 ?
Solution
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.
Answered By - James Elliott Answer Checked By - Robin (WPSolving Admin)