saadlulu
saadlulu

Reputation: 1395

move_uploaded_file not working in ubuntu 10.04

hey guys, am having a bit of a problem here, move_uploaded_file is not actually working at all, and its showing some warnings in my terminal.

my code:


$name =  $_FILES['file']['name'];
$size =  $_FILES['file']['size'];
$type =  $_FILES['file']['type'];
$error =  $_FILES['file']['error'];
$temp =  $_FILES['file']['tmp_name'];
$destination = "uploads/";

if($size > 10000000) {
    exit("file size is too big, Max allowed size is 10Mbs");
}

if($type == "application/x-ms-dos-executable") {
    exit("not allowed file formatt.");
}

move_uploaded_file($temp, $destination.$name);

terminal:

[Sat May 14 15:14:01 2011] [error] [client ::1] PHP Warning:  move_uploaded_file(uploads/gears_16.png): failed to open stream: Permission denied in /var/www/alex/fileupload/upload.php on line 18, referer: http://localhost/alex/fileupload/
[Sat May 14 15:14:01 2011] [error] [client ::1] PHP Warning:  move_uploaded_file(): Unable to move '/tmp/phpMxKzds' to 'uploads/gears_16.png' in /var/www/alex/fileupload/upload.php on line 18, referer: http://localhost/alex/fileupload/


and files wont move, the source, destination and file permissions are 777. this is getting frustrating :(

Upvotes: 0

Views: 6373

Answers (2)

Zeeshan
Zeeshan

Reputation: 21

  • In Ubuntu, you have to give the destination directory permission to daemon user.
  • In my case, i have my workspace in /opt/lampp/htdocs/students/ and have a folder like this /opt/lampp/htdocs/students/uploadedFilesDestination.
  • I want to put my uploaded files into uploadedFilesDestination folder. The thing here is that ubuntu's kernel/threads have to have the permission to the target directory.
  • You might have to use the following piece of command to do so.
    open terminal and follow the command

sudo chown daemon /opt/lampp/htdocs/student/uploadedFilesDestination

daemon is important. daemon is the *user for kernel permissions.

Upvotes: 0

0xAli
0xAli

Reputation: 1059

sudo chown alex -R /var/www

sudo chgrp www-data -R /var/www

sudo chmod 0751 -R /var/www

//mentioned here http://ubuntuforums.org/showthread.php?t=560592

Upvotes: 2

Related Questions