3

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

2 Answers 2

4

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/
Sign up to request clarification or add additional context in comments.

3 Comments

@user873286 See my update about apache being able to write to your target folder then.
Thanks solved problem, problem was with the permission. P.S: I am new in stackoverflow, is it possible to mark this as solved or anything else or I just need to live as it is?
@user873286 Welcome to SO. Click the green checkmark beside my answer to "Accept" it if it solves your issue.
2

Does your code have permission to write files to /tmp?

Do the apache error logs say anything?

1 Comment

How can I check whether it has or no?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.