Page 1 of 1

php uploading problem on ubuntu

Posted: Mon Oct 17, 2011 8:12 pm
by toniknik1982
I'm using Ubuntu 11.04 Desktop, I just installed LAMP on it because I'm going to use this as my test web server. I have problem on uploading file (usually .jpg) using PHP, file appears to be uploaded successfully but when i try to view my "upload" folder file isn't there. I modified the document root location in apache2 it is "/home/guesthere/php_practice" and the "upload" folder is a sub-folder of php_practice. Here's my code:

index.html

Code: Select all

<html>
<head><title>Main</title></head>
<body>
<form action = 'Upload.php' method = 'post' enctype = 'multipart/form-data'>
<input type = 'file' name = 'fUpload'>
<br>
<br>
<input type = 'submit' name = "Submit" value = 'Submit'>
</form>
</body>
</html>

Upload.php

Code: Select all

<html>
<head><title>To_Upload</title></head>
<body>
<?php
$name = $_FILES['fUpload']['name'];
$tmp = $_FILES['fUpload']['tmp_name'];
$folder = "upload/";

//to view the file name
echo $name . "<br>";

//to view the actual location in tmp folder
echo $tmp . "<br>";

move_uploaded_file($tmp,$folder);

echo (is_uploaded_file($_FILES['fUpload']['tmp_name']));

</body>
</html>

Here's the Output:
[text]
test1.jpg
/tmp/phpCv1asD
1
[/text]
Please help......

Re: php uploading problem on ubuntu

Posted: Mon Oct 17, 2011 8:36 pm
by Celauran
Does apache have write permission to that directory? Have you checked your access/error logs? What if you add the following?

Code: Select all

echo file_exists($folder . "/" . $tmp);

Re: php uploading problem on ubuntu

Posted: Tue Oct 18, 2011 2:22 am
by toniknik1982
thanks a lot Celauran

On your first question: how am I going to do that? Do I have to make another group name "apache"? or use the www-data? which I think the default user after installing apache. What command should i invoke? please guide really need your help it's my first time of doing this... btw here is the result after ll command. :?
drwxrwxrwx 3 guesthere guesthere 4096 2011-10-18 13:38 php_practice/

Error log
[Tue Oct 18 13:39:08 2011] [error] [client 127.0.0.1] PHP Warning: move_uploaded_file(): Unable to move '/tmp/php2pyHbG' to 'upload/' in /home/guesthere/php_practice/Pupload.php on line 12, referer: http://localhost/index.html

Your reply is very much appreciated... Thanks in advance...

- right now I'm still trying to figure this out:

Re: php uploading problem on ubuntu

Posted: Tue Oct 18, 2011 4:18 am
by ouchiko
upload/ is _relative_ to the execution of the script, make sure the directory exists and permissions are set.

You can change permissions with chown or chmod, however chmod should be sufficient. Look it up :)

Re: php uploading problem on ubuntu

Posted: Tue Oct 18, 2011 6:50 am
by Celauran
No need to create a new group. Either chown /home/guesthere/php_practice/upload so www-data is its group, or chmod 777 to make it world writable. Based on the apache error, I'm guessing it's a permissions issue.

Also, while I suppose it isn't so important on your personal test machine, I wouldn't leave /home/guesthere/php_practice world writable.

Re: php uploading problem on ubuntu

Posted: Wed Oct 19, 2011 7:05 pm
by toniknik1982
Thanks a lot for giving me hints on how to make this work! It helps a lot...
This also help.
http://superuser.com/questions/19318/ho ... s-in-linux