Jump to content

PHP rename() permission error

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
phpforfun

phpforfun

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,236 posts
So, I am trying to use the following script in a new site, pretty basic
$orig = $original[$key];

if($orig !== $newname2){

		rename("../images/catalog/$orig", "../images/catalog/$newname2");

}
And I keep getting permission denied errors, I looked it up on php.net, and it said to add fopen ® and fclose, so I changed it to this:
$orig = $original[$key];

if($orig !== $newname2){

		$fileHand = fopen("../images/catalog/$orig", 'r');

	    fclose($fileHand);

		rename("../images/catalog/$orig", "../images/catalog/$newname2");

}
And STILL get the errors.
The images permissions are set to 777, and the chown is right as well.

Any idea?

Merry Christmas!
Checkout my new forum! http://adminreference.com/

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Programming on Christmas, now that is a programmer! lol
Merry Christmas to you as well.

What is the exact error? Who is PHP being executed as (nobody, root, the user)? Who owns the file? What was the purpose of the fopen with R, just to see if you could read it? Have you tried using a full path instead of a relative path? Perhaps you could try copy() and unlink() functions and see if that works?

From your original post and the code you posted it should work...

#3
phpforfun

phpforfun

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,236 posts
CHanged the paths to the full paths, here is the error.

Quote

Warning: rename(/home/imakeco/public_html/images/catalog/images5 (4th copy).jpeg,/home/imakeco/public_html/images/catalog/aaaaaaaaaaaaaaaaaaaaaaa.jpeg) [function.rename]: Permission denied in /home/imakeco/public_html/admin/adminfiles/manage_pictures-unassigned.php on line 51

manage_pictures-unassigned.php has the same permissions as the images..

Yeah, im programming on xmas :P I am rather excited about this lil script I got going. lol

Edited by phpforfun, 25 December 2008 - 09:50 AM.

Checkout my new forum! http://adminreference.com/

#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
What permissions does catalog/ have? If you SSH in as that user can you touch a file in that directory? Can you manually move the file to the new name?

#5
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
$5 says you uploaded the file as some user, and php, which is running as nobody, cannot modify the file since it is not the owner. To circumvent this issue, create an FTP layer.

#6
phpforfun

phpforfun

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,236 posts

Quote

imakeco@imakecomputers.com [~/www/admin/adminfiles]# ls -l |grep manage_pictures-unassigned.php
-rwxrwxrwx 1 imakeco imakeco 3055 Dec 25 12:05 manage_pictures-unassigned.php
imakeco@imakecomputers.com [~/www/admin/adminfiles]# ls -l ../../images |grep catalog
drwxr-xr-x 2 imakeco imakeco 4096 Dec 25 12:09 catalog/
imakeco@imakecomputers.com [~/www/admin/adminfiles]# ls -l ../../images/catalog
total 64
drwxr-xr-x 2 imakeco imakeco 4096 Dec 25 12:09 ./
drwxrwxrwx 3 imakeco imakeco 4096 Dec 25 02:54 ../
-rwxrwxrwx 1 imakeco imakeco 7100 Dec 19 16:08 8.jpg*
-rwxrwxrwx 1 imakeco imakeco 3015 Dec 25 02:51 images\ (3rd\ copy).jpeg
-rwxrwxrwx 1 imakeco imakeco 3015 Dec 25 02:51 images\ (4th\ copy).jpeg
-rwxrwxrwx 1 imakeco imakeco 3015 Dec 25 02:51 images\ (another\ copy).jpeg
-rwxrwxrwx 1 imakeco imakeco 3015 Dec 25 02:51 images\ (copy).jpeg
-rwxrwxrwx 1 imakeco imakeco 3015 Dec 25 01:34 images.jpeg*
-rwxrwxrwx 1 imakeco imakeco 2932 Dec 25 02:51 images0\ (3rd\ copy).jpeg
-rwxrwxrwx 1 imakeco imakeco 2932 Dec 25 02:51 images0\ (4th\ copy).jpeg
-rwxrwxrwx 1 imakeco imakeco 2932 Dec 25 02:51 images0\ (another\ copy).jpeg
-rwxrwxrwx 1 imakeco imakeco 2932 Dec 25 02:51 images0\ (copy).jpeg
-rwxrwxrwx 1 imakeco imakeco 2932 Dec 25 02:50 images0.jpeg
-rwxrwxrwx 1 imakeco imakeco 2505 Dec 25 02:51 images2\ (3rd\ copy).jpeg
-rwxrwxrwx 1 imakeco imakeco 2505 Dec 25 02:51 images2\ (4th\ copy).jpeg
imakeco@imakecomputers.com [~/www/admin/adminfiles]#

Quote

Warning: rename(/home/imakeco/public_html/images/catalog/images0 (3rd copy).jpeg,/home/imakeco/public_html/images/catalog/aaaaaaaaa.jpeg) [function.rename]: Permission denied in /home/imakeco/public_html/admin/adminfiles/manage_pictures-unassigned.php on line 53
images0 (3rd copy).jpeg was renamed to aaaaaaaaa.jpeg and assigned to product ID 24

Warning: rename(/home/imakeco/public_html/images/catalog/images2 (4th copy).jpeg,/home/imakeco/public_html/images/catalog/bbbbbbbbb.jpeg) [function.rename]: Permission denied in /home/imakeco/public_html/admin/adminfiles/manage_pictures-unassigned.php on line 53
images2 (4th copy).jpeg was renamed to bbbbbbbbb.jpeg and assigned to product ID 25

Warning: rename(/home/imakeco/public_html/images/catalog/images0 (4th copy).jpeg,/home/imakeco/public_html/images/catalog/cccccccccc.jpeg) [function.rename]: Permission denied in /home/imakeco/public_html/admin/adminfiles/manage_pictures-unassigned.php on line 53
images0 (4th copy).jpeg was renamed to cccccccccc.jpeg and assigned to product ID 22

Warning: rename(/home/imakeco/public_html/images/catalog/images0.jpeg,/home/imakeco/public_html/images/catalog/ddddddddd.jpeg) [function.rename]: Permission denied in /home/imakeco/public_html/admin/adminfiles/manage_pictures-unassigned.php on line 53
images0.jpeg was renamed to ddddddddd.jpeg and assigned to product ID 23

I thought 755 and imakeco:imakeco on /catalog would be enough, guess I was wrong.

I will refund you $5 on your next billing statement for stssquad :P
Checkout my new forum! http://adminreference.com/