简体   繁体   中英

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:(

sudo chown alex -R /var/www

sudo chgrp www-data -R /var/www

sudo chmod 0751 -R /var/www

//这里提到http://ubuntuforums.org/showthread.php?t=560592

  • 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM