PROBLEM CHANGING FILE PERMISSIONS

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
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

I think that is exactly what is happening with you, that is why I posted it. I had the same problem where a web photo album would let users upload pictures, but then when I login via SSH with my normal user, I couldn't delete or rename the uploaded files, and would have to get the server admin to do it for me. I then changed my script to chmod the uploaded files, and chmod'ing them would work for some modes but not all. Like I could tell php to chmod a file to execute access, but couldn't tell it to give everyone access. If you have that problem, I don't know what you can do, but talk to your server admin, he might put your user in the same group that php is in, i dunno.

Forget php all together, if you want to see if I'm right, login to your server with telnet or better SSH. An "ls -als" will tell you the files in a directory with the chmod values over on the left. And on Unix/Linux, chmod is also a program, so just chmod 0745 yourfile to see if you can. That ls will also tell you the owner/group the file is part of.
nirma78
Forum Commoner
Posts: 42
Joined: Wed Sep 17, 2003 2:02 pm

Post by nirma78 »

Thanks for your reply..

I am really stuck with this thing here...

I tried going in there and did ls-la

the file is owned by the server says "apache".

I also tried doing chmod 0745 on the file but it says operation not permitted.

So what do you think can be done in this case to solve my problem , I mean is it doable in php script with owning the file or I have to be in the group for that.

Please help...
Thanks in advance
nirma78
Forum Commoner
Posts: 42
Joined: Wed Sep 17, 2003 2:02 pm

Post by nirma78 »

hey guys !! Its working now !! :)

here is my working code :

Code: Select all

<?php
$uploaddir = "check/" . $_FILES['userfile']['name'];
$up = move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir);
chmod($uploaddir,0644);
?>
earlier it was :

Code: Select all

<?php
$uploaddir = "check/" . $_FILES['userfile']['name'];
chmod($uploaddir,0644);
$up = move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir);
?>
:!: NOTE the position of the statement chmod ()

THANKS to all who helped !!!
User avatar
Leviathan
Forum Commoner
Posts: 36
Joined: Tue Sep 23, 2003 7:00 pm
Location: Waterloo, ON (Currently in Vancouver, BC)

Post by Leviathan »

Ok, so I was on the right track with telling you to chmod the uploaded file; I just didn't understand fully how PHP handled uploads. Glad to hear you have it working.
CaTrix
Forum Newbie
Posts: 1
Joined: Thu Sep 25, 2003 11:04 pm

file permissions

Post by CaTrix »

hi people,

i hope you guys can help me too. my problem is when i try to upload files it gives me the following error:

Warning: move_uploaded_file(cao1/0001216.vsd) [function.move-uploaded-file]: failed to create stream: Permission denied in /home/webman/myuploadnetdia.php on line 13

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpdJN5ji' to 'cao1/0001216.vsd' in /home/webman/myuploadnetdia.php on line 13

The weird thing is when i try to upload it in cao directory with a specific filename format. it allows me to upload the file..

pls help.
Post Reply