Page 1 of 2
PROBLEM CHANGING FILE PERMISSIONS
Posted: Wed Sep 24, 2003 3:36 pm
by nirma78
Hi !
I am trying to upload a file. It uploads it fine, but the problem is when I try to open the file it says "Access Denied".
I tried to change the permissions for the file but it gives me error.
Please help.
Thanks in advance
My Code :
Code: Select all
<?php
$uploaddir = "check/" . $_FILES['userfile']['name'];
chmod($uploaddir,644);
$up = move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir);
//var_dump($up);
if($up)
{
echo "File uploaded";
}
else
{
echo "Not uploaded";
}
?>
?>
Posted: Wed Sep 24, 2003 3:41 pm
by Leviathan
Would a chmod to 644 on the uploaded file help?
Posted: Wed Sep 24, 2003 3:43 pm
by nirma78
Well my system administrator asked me to change it to 644.
If not that , then what do you think will help.
Thanks for your reply.
Posted: Wed Sep 24, 2003 3:46 pm
by nirma78
I tried changing it from 644 to 777, but still the same error !!
Please help
Thanks in advance
Posted: Wed Sep 24, 2003 4:35 pm
by Leviathan
Correct me if I'm wrong, but aren't you chmodding the directory that you're putting the file in, not the file itself?
Posted: Wed Sep 24, 2003 7:25 pm
by nirma78
Thanks for your reply.
I think its for the file I think, I mean its like
Code: Select all
<?php
$uploaddir = "check/" . $_FILES['userfile']['name'];
chmod($uploaddir,777);
?>
and $_FILES['userfile']['name'] gives me the name of the file that I am uploading and I want to name it the same where it is getting uploaded .. so isnt it chmodding the file ??
I am not sure
Thanks
Posted: Wed Sep 24, 2003 7:37 pm
by Judas
b.t.w.
does your script have the right permissions set for this job.
and what kind of os the server is running on.
so...
check chmod on dest. location, exec. script file.
learn more about telnet...
Posted: Wed Sep 24, 2003 7:51 pm
by nirma78
you asked "does your script have the right permissions set for this job."
what does this exactly mean - i mean I m not able to understand permissions for what ?
I do have write permissions on the server
I am changing the permissions for the file I am uploading
what else do I have to know for this
and could you please explain what do you mean when you have written "check chmod on dest. location, exec. script file.
" I couldnt understand
Posted: Wed Sep 24, 2003 8:22 pm
by Leviathan
Look again where and when you're calling chmod. You create a variable called $uploaddir, which, at least to me, signifies a directory. If you mean it to be a file, I'd change the name so that you don't confuse yourself. Then, you try to upload the file. What you don't do *after* you upload the file is set the permission on the file.
I'm guessing that $up is set, so the script echoes "File uploaded" but you can't get access to the file? If so, put the chmod statement in after the call to move_uploaded_file.
Posted: Wed Sep 24, 2003 8:38 pm
by nirma78
Thanks for your reply.
Well this is my code :
Code: Select all
<?php
$name = $_FILES['userfile']['name'];
$uploaddir = "check/" . $_FILES['userfile']['name'];
chmod($uploaddir,777);
$up = move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir);
chmod($uploaddir,777);
//chmod($name,0644);
//var_dump($up);
if($up)
{
}
else
{
echo "Not uploaded";
}
?>
?>
so now tell me if you are telling to chmod for the file how do I do that, as in how will get only the file name..
I tried chmodding after move_uploaded_file() but it gives me a warning message :
chmod(): No such file or directory in /home/httpd/htdocs/gbcb/upload_app_files.php on line 16
Please help
Thanks again
Posted: Wed Sep 24, 2003 8:52 pm
by Leviathan
Right; you can't just chmod the dir, but the dir and filename together. So:
Code: Select all
<?php
chmod($uploaddir.$_FILES['userfile']['tmp_name'],644);
?>
Posted: Thu Sep 25, 2003 12:07 am
by Pyrite
Something to keep in mind, this is at least true for me..
If you are using an upload script, the file you upload is created (under Linux/Unix) as the owner that the web server runs under. And if you are a different user on the system, then you are not the owner of the uploaded file, even if it is in your home directory.
Ie. If Apache runs under user nobody in group nobody, then PHP will create an uploaded file with the owner nobody and group nobody. You see. Same thing if your web servers runs under user httpd or whatever user/group it is. PHP will create files that way too.
Posted: Thu Sep 25, 2003 3:11 am
by twigletmac
Moved to PHP - Normal, it's not a database question.
Mac
Posted: Thu Sep 25, 2003 6:17 am
by Judas
what kind of OS ? (Unix,Windows,Sol....) ???
what kind off permissions does the executing script file has ???
(the executing script file is the file where from your script is running)
when the script file hasn't got the right permissions set . it can not do the job.
web/sample.php
Code: Select all
<?php
$uploaddir = "check/" . $_FILESї'userfile']ї'name'];
chmod($uploaddir,0644);
$up = move_uploaded_file($_FILESї'userfile']ї'tmp_name'], $uploaddir);
//var_dump($up);
if($up)
{
echo "File uploaded";
}
else
{
echo "Not uploaded";
}
?>

note the added "0" in the chmod mode string
- telnet or ftp to "web/"
and then chmod the map with "chmod 0777 web" (telnet syntax)
the location of sample.php
and then chmod the script file with "chmod 0777 sample.php" (telnet syntax)
this file now has permissions to do what ever.
Dude just chmod the script file with a ftp prog or telnet OK. pfff

Posted: Thu Sep 25, 2003 8:31 am
by nirma78
Thank you all of you for your replies.
Well this is where I am now :
Levithian :
Code: Select all
<?php
<?php
chmod($uploaddir.$_FILES['userfile']['tmp_name'],644);
?>
?>
I tried doing it but it still gives me the error !!
Warning: chmod(): No such file or directory in /home/httpd/htdocs/gbcb/upload_app_files.php on line 16
Pyrite : I think what you told might be happening with me. The file is not owned by me,the owner is the server where it is running the file. So do you think that might be the problem here since it doesnt allow me to change permissions on some other's owned files ??
Judas : Well I am on Windows and the server is on Unix. ie I am coding from windows and running on unix server.
also I tried doing :
but still not working. now for doing ftp or telnet is it required that I should be the owner of the file, coz in my case the owner of the file is apache, the server where it is running the file.
PLEASE HELP !!
Thanks in advance.