1

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

Community
  • 1
  • 1
user2209743
  • 65
  • 2
  • 6
  • Have you enabled `error_reporting`? There should be a message, unless your `/` root directory is world-writable. (No, don't do this!) – mario Mar 26 '13 at 01:24
  • add this to get what the error is ,it seems a sort of permission problem , any way try the code to get the errror Code: $error = error_get_last(); echo $error['message']; – internals-in Mar 26 '13 at 01:26
  • mario is correct, you should or shall I say MUST check the permissions of your directories. – Mark Mar 26 '13 at 01:26
  • error reporting is enabled – user2209743 Mar 26 '13 at 01:30
  • Have you made sure that the current working directory has the correct permissions? (read, write, execute (777)) – Daryl Gill Mar 26 '13 at 01:32
  • it does, that was one of the first things I checked – user2209743 Mar 26 '13 at 01:34
  • You need to check the permissions on the `/downloads/` dir path. Doesn't matter that your script is in `/server`. the mkdir is trying to work in `/downloads`. – Marc B Mar 26 '13 at 05:01

2 Answers2

0

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
heiglandreas
  • 3,803
  • 1
  • 17
  • 23
0

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
Falko
  • 17,076
  • 13
  • 60
  • 105
Prashant Shukla
  • 329
  • 1
  • 2
  • 17