0
votes

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

1
It seems your script haven't permission to move the file.Saleh
visit this page htmlite.com/php042.phpSaleh
On a separate note, it's better to maintain a file type whitelist as opposed to a blacklist, in most cases.Nick
The folder you want to upload to is /var/www/alex/fileupload/uploads or /var/www/alex/uploads And the permission is 777 right?0xAli
@nick very interesting, ill add it up :)saadlulu

1 Answers

2
votes

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