I've am trying to set up a small file sharing server on my home's local network and am running into some big problems with the uploader. the step it seems to be failing on is the directory creation step however, when I first posted this there were no errors in the Apache log files however, that turned out to be the result of a permission problem with the lag files.
this are the relevant log entries.
[Mon Mar 25 18:43:05 2013] [error] [client 10.0.0.17] PHP Warning: mkdir(): Permission denied in /server/upload_movie.php on line 10, referer: http://10.0.0.17/upload_movie.html
it confuses me because I have run sudo chmod 0777 /server/* sudo chmod 0777 /server with /server/ being the rood directory.
my code is as follows
<?php
echo "starting". "<br>";
$allowedExts = array("mp4", "mpg", "avi", "mkv");
$extension = end(explode(".", $_FILES["uplodedfile"]["name"]));
echo "filetype parsed". "<br>";
$path = "/downloads/movies/unsorted/";
echo "checking upload directory". "<br>";
if(!is_dir($path)){
echo "upload directory not found, creating...";
if (mkdir($path,0777,true))
{
echo "directory creation complete". "<br>";
}
else
{
echo "directory creation failed at ".$path."<br>";
}
}
echo "checking file". "<br>";
if (false)
{
echo "filetype and size passed". "<br>";
if ($_FILES["uplodedfile"]["error"] > 0)
{
header('Location: upload_failure.php?file='.$_FILES["uplodedfile"]['name'].'&error='.$_FILES["uplodedfile"]["error"]);
exit();
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("upload/" . $_FILES["uplodedfile"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists on server. ". "<br>";
}
else
{
echo "creating perminant copy of file". "<br>";
move_uploaded_file($_FILES["uplodedfile"]["tmp_name"],
$path."/" . $_FILES["uplodedfile"]["name"]);
echo "Stored in: " . "movie_uploads/" . $_FILES["file"]["name"]. "<br>";
}
}
header('Location: upload_success.php?type=movie');
exit();
}
else
{
echo "error:<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Name: " . $_FILES["file"]["name"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
echo "extension: ".$extension;
exit();
// echo "Invalid file";
}
?>
the output is as follows
starting
filetype parsed
checking upload directory
upload directory not found, creating...directory creation failed at /downloads/movies/unsorted/
checking file
error:
Type:
Name:
Size: 0 kB
Temp file:
extension:
and the code calling it is
<form enctype="multipart/form-data" action="upload_movie.php" method="POST">
<input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
i have tried all the suggestions in PHP mkdir: Permission denied problem and I have selinux turned off. I am using fedora 17. the server is being run on an ext4 partition which contains nothing else.
as was suggested in comments, i tried $error = error_get_last(); echo $error['message']; which yealded Undefined index: file
You seem to have set the correct permissions to the /server-directory. But your server wants to write to the /downloads- directory. You should be up and running with this command:
Sudo chmod 777 /download
Your error message tells everything in it. This is file write permission problem. If you want to write your file in /downloads/movies/unsorted/ then you need to set write permission to this directory for all (777). But you are saying, you already checked permission for the downloads directory, but you might not set permission for recurring directories. So try below command before uploading file.
Sudo chmod -R 777 /download