php uploading problem on ubuntu

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
toniknik1982
Forum Newbie
Posts: 12
Joined: Mon Oct 17, 2011 7:01 pm

php uploading problem on ubuntu

Post 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......
Last edited by Benjamin on Mon Oct 17, 2011 8:23 pm, edited 1 time in total.
Reason: Added [syntax=php|sql|css|javascript] and/or [text] tags.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php uploading problem on ubuntu

Post 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);
toniknik1982
Forum Newbie
Posts: 12
Joined: Mon Oct 17, 2011 7:01 pm

Re: php uploading problem on ubuntu

Post 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:
ouchiko
Forum Commoner
Posts: 35
Joined: Sun Oct 09, 2011 6:54 pm
Location: London

Re: php uploading problem on ubuntu

Post 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 :)
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php uploading problem on ubuntu

Post 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.
toniknik1982
Forum Newbie
Posts: 12
Joined: Mon Oct 17, 2011 7:01 pm

Re: php uploading problem on ubuntu

Post 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
Post Reply