Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP upload problem

I have php upload problem, I have the following code:

define('GW_UPLOADPATH', '/var/www/train/ch5/images/');
$name = $_POST['name'];
$score = $_POST['score'];
$screenshot = $_FILES['screenshot']['name'];

$target = GW_UPLOADPATH.$screenshot;
echo $_FILES['screenshot']['tmp_name'].'<br/>';
move_uploaded_file($_FILES['screenshot']['tmp_name'], $targe)
or die("Upload Error!");

I get upload error! The temporary file where file is uploaded is:

/tmp/php9Khayp

but in /tmp I can not find this file. I am working on Ubuntu 10.10. Can anyone say me where is the problem?

apache error.log:[Wed Aug 10 20:54:17 2011] [error] [client ::1] PHP Warning: move_uploaded_file(/var/www/train/ch5/images/phizsscore.gif): failed to open stream: Permission denied in /var/www/train/ch5/addscore.php on line 22, referer: http://localhost/train/ch5/addscore.php [Wed Aug 10 20:54:17 2011] [error] [client ::1] PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpmkZEr3' to '/var/www/train/ch5/images/phizsscore.gif' in /var/www/train/ch5/addscore.php on line 22, referer: http://localhost/train/ch5/addscore.php [Wed Aug 10 20:54:18 2011] [error] [client ::1] File does not exist: /var/www/favicon.ico

like image 835
user873286 Avatar asked Jul 09 '26 20:07

user873286


1 Answers

You have a typo. $targe should be $target.

move_uploaded_file($_FILES['screenshot']['tmp_name'], $targe)
                ---------------------------------------^^^^^^

Otherwise, you will never be able to see the file in /tmp because it only persists for the lifetime of the PHP script. As soon as the script execution completes, the file will be cleaned up. You can't ever access it on disk after the script terminates unless a successful call to move_uploaded_file() is made.

UPDATE

If the $target variable is not the problem, make sure that the Apache web server user (www-data, httpd, apache are possibilites) has write access to your target /var/www/train/ch5/images/:

# assuming the Apache user is apache...
sudo chown root:apache /var/www/train/ch5/images/
sudo chmod g+rwx /var/www/train/ch5/images/
like image 166
Michael Berkowski Avatar answered Jul 13 '26 17:07

Michael Berkowski