move_uploaded_file not working

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

User avatar
nissar
Forum Newbie
Posts: 10
Joined: Tue Jul 31, 2007 4:37 am

move_uploaded_file not working

Post by nissar »

Hi dears,

I have a problem with move_uploaded_file function in LINUX server.

Actually the document root was "/var/www/html/proj" initially and move_uploaded_file function was really working fine. :)

Then due to less space in "/var" volume, I have moved my project to "/usr/PHP/proj" folder. Then the whole project is now working fine except move_uploaded_file. :(

move_uploaded_file showing some permission problem. :cry: :cry:

I had given full permission (777) for "/usr" and "/usr/PHP/proj/upload" folders. But still uploading is not working.

Please anyone can help me.. It is really urgent..please..

Many thanks for giving me a valuable advice...

regards
Nissar
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

chown the files to proper user and see

Code: Select all

chown apache:apache  uploaddirectory
User avatar
nissar
Forum Newbie
Posts: 10
Joined: Tue Jul 31, 2007 4:37 am

Post by nissar »

Thank you for your reply.

I have done chown

Code: Select all

chown apache:apache /usr/PHP/proj/uploads/Blogfiles
and tried to upload, then following error is displayed.

Warning: move_uploaded_file(/usr/PHP/proj/uploads/BlogFiles/blogimage_1b334e_blogimage.jpg): failed to open stream: Permission denied in /usr/PHP/proj/admin/classes/common/class.upload.php on line 19

Warning: move_uploaded_file(): Unable to move '/tmp/php2LJLJx' to '/usr/PHP/proj/uploads/BlogFiles/blogimage_1b334e_blogimage.jpg' in /usr/PHP/proj/admin/classes/common/class.upload.php on line 19

Please could you advice how I should get this working..

regards
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

pasting your code could be of some help..
User avatar
nissar
Forum Newbie
Posts: 10
Joined: Tue Jul 31, 2007 4:37 am

Post by nissar »

When I used

Code: Select all

echo "strTmpName = $strTmpName <br />";
			echo "target_file = $target_file <br />";
			move_uploaded_file($strTmpName, $target_file);
it showed result as:

Code: Select all

strTmpName = /tmp/php1lmvBB
target_file = /usr/PHP/proj/uploads/BlogFiles/blogimage_3d51af_blogimage.jpg

Warning: move_uploaded_file(/usr/PHP/proj/uploads/BlogFiles/blogimage_3d51af_blogimage.jpg): failed to open stream: Permission denied in /usr/PHP/proj/admin/classes/common/class.upload.php on line 21

Warning: move_uploaded_file(): Unable to move '/tmp/php1lmvBB' to '/usr/PHP/proj/uploads/BlogFiles/blogimage_3d51af_blogimage.jpg' in /usr/PHP/proj/admin/classes/common/class.upload.php on line 21


But all the code is still working when I am changing my Document Root to "/var" volume. What could be the problem when working under "/usr" volume.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

still it is permissions problem... do a

Code: Select all

chown -R apache:apache /usr/PHP/proj/uploads/Blogfiles
Between , is the user of apache is apache or nobody??
User avatar
nissar
Forum Newbie
Posts: 10
Joined: Tue Jul 31, 2007 4:37 am

Post by nissar »

I have tried

Code: Select all

chown -R apache:apache /usr/PHP/proj/uploads/Blogfiles
and still error.

How I will get the user name of apache?
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

do a

Code: Select all

ps -aux | grep httpd
or check the httpd.conf file for User
Last edited by dude81 on Tue Jul 31, 2007 7:06 am, edited 1 time in total.
User avatar
nissar
Forum Newbie
Posts: 10
Joined: Tue Jul 31, 2007 4:37 am

Post by nissar »

nissar wrote: How I will get the user name of apache?
Anyway there is a user "apache" in the users list.

Please could you advice then?
User avatar
nissar
Forum Newbie
Posts: 10
Joined: Tue Jul 31, 2007 4:37 am

Post by nissar »

dude81 wrote:do a

Code: Select all

ps -aux | grep httpd
I got the following result:

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.3/FAQ
root 2482 0.0 0.9 19636 10248 ? Ss 10:19 0:00 /usr/sbin/httpd
root 2499 0.0 0.6 14528 6576 ? Ss 10:19 0:00 /usr/local/apache/bin/httpd -k start
daemon 2504 0.0 0.7 15260 7628 ? S 10:19 0:09 /usr/local/apache/bin/httpd -k start
daemon 2505 0.0 0.7 15320 7592 ? S 10:19 0:08 /usr/local/apache/bin/httpd -k start
daemon 2506 0.0 0.7 15244 7616 ? S 10:19 0:09 /usr/local/apache/bin/httpd -k start
daemon 2507 0.0 0.7 15224 7592 ? S 10:19 0:10 /usr/local/apache/bin/httpd -k start
daemon 2508 0.0 0.7 15220 7584 ? S 10:19 0:09 /usr/local/apache/bin/httpd -k start
daemon 3172 0.0 0.7 15224 7588 ? S 10:19 0:08 /usr/local/apache/bin/httpd -k start
daemon 3173 0.0 0.7 15240 7760 ? S 10:20 0:10 /usr/local/apache/bin/httpd -k start
daemon 3780 0.0 0.7 15224 7588 ? S 11:03 0:07 /usr/local/apache/bin/httpd -k start
daemon 4049 0.0 0.7 15228 7584 ? S 11:30 0:06 /usr/local/apache/bin/httpd -k start
apache 5659 0.8 2.1 32460 21812 ? S 15:41 0:54 /usr/sbin/httpd
apache 5668 0.3 2.0 29860 21460 ? S 15:42 0:25 /usr/sbin/httpd
apache 5674 0.4 2.0 32152 21548 ? S 15:45 0:26 /usr/sbin/httpd
apache 5725 0.5 2.1 32904 22176 ? S 15:52 0:32 /usr/sbin/httpd
apache 5746 0.4 2.1 32448 21796 ? S 15:53 0:23 /usr/sbin/httpd
apache 5775 0.8 1.7 28756 18076 ? S 15:56 0:47 /usr/sbin/httpd
apache 6225 0.4 1.7 28792 18192 ? S 16:41 0:12 /usr/sbin/httpd
apache 6429 0.1 1.6 25852 17380 ? S 17:18 0:00 /usr/sbin/httpd
daemon 6555 0.2 0.6 14792 7132 ? S 17:28 0:00 /usr/local/apache/bin/httpd -k start
root 6560 0.0 0.0 4316 680 pts/0 S+ 17:28 0:00 grep httpd




Also,
please note there is another apache (apache2) in /usr/local/apache folder..

Nissar
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

You look like running two webservers or I'mnot sure, but I see other user daemon there.. its defnitely user problem.. try to give a proper webserver user permissions on to the document root
User avatar
nissar
Forum Newbie
Posts: 10
Joined: Tue Jul 31, 2007 4:37 am

Post by nissar »

But second one was installed only before few days, but there was the problem before I am installing the apache2.

Also, I have checked phpinfo() and the user/group is shown as:

User/Group: apache(48)/48

What could be the problem please advice..
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

Its user daemon.. between what flavor of linux are you using? make it as user apache(this is done in corresponding httpd.conf file) or change the chown -R the files to user daemon(do this at your own risk)
User avatar
nissar
Forum Newbie
Posts: 10
Joined: Tue Jul 31, 2007 4:37 am

Post by nissar »

I have checked in http.conf and saw the User & Group as "apache".

If I change User & Group to "daemon" in http.conf, and folder to "daemon", does this cause any problem to work my proj

:wink: ?
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

then why is this showing daemon

Code: Select all

daemon 2504 0.0 0.7 15260 7628 ? S 10:19 0:09 /usr/local/apache/bin/httpd -k start
Be sure that you have checked for the right apache.

daemon is not suggestable as there are many daemons run on linux, if you give permission to daemon, the other
daemon programs can access the webfiles.
Post Reply