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
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With