Page 1 of 1

how to chmod-777 a DIRECTORY (not a file) via PHP?

Posted: Thu Aug 01, 2002 7:23 am
by mazzogeddon
Hi @all,

I am working on an upload-script (use for the webmaster only). It works well if I put the directory for the files to upload on chmod-777 (by telnet or ftp). The script is used to upload new files other user can download and at the same time updating the database with the file infos, descriptions, associated links and further stuff.

I want this directory to be a 'normal' chmod-755 (because it´s accessible for any user), and only for the process of uploading it should be set on 777.

The chmod('filename', 0755)-function in PHP does only work with existing files, not for directories.
Can anyone help?

thanx,
Mazzo

Posted: Thu Aug 01, 2002 7:31 am
by Toneboy
Erm, can't you do it through your FTP client? (Guessing, just learning this myself)

Posted: Thu Aug 01, 2002 7:42 am
by mazzogeddon
sure, but I want to do it automatically and not by hand. If I have to change the rights of the directories by ftp every time I upload something i dont need any upload-script.

Posted: Thu Aug 01, 2002 8:39 am
by Johnm
You can do this with a system command if the web server is running as the person that owns the file or directory. This alone could be a problem unless the web server is running as root... of which is a very poor idea.

Direwolf

Posted: Thu Aug 01, 2002 9:05 am
by mazzogeddon
OK, but are there no functions to change the rights of an directory by PHP?

Posted: Thu Aug 01, 2002 9:19 am
by Johnm
Look up the function:
system()

Direwolf

Posted: Thu Aug 01, 2002 9:22 am
by twigletmac
Was just going to say that but was a little slow. There's also exec() though.

Mac

Posted: Thu Aug 01, 2002 10:00 am
by mazzogeddon
thanx a lot! That was exactly what I was looking for. (I used passthru() in the end)

But now I get strange double-slashes in the $name of the file I selected for upload. That makes it impossible to find the file.
If I change them with stripslashes I guess that I changed the type of the variable to a string.

Here´s my form:
<form action=\"uploader.php\" method=\"post\">
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"262144000\"<br>
<input type=\"file\" name=\"fupload\" size=\"40\"><br>
...(following several database commands - this works, I tested it)...
<input type=\"submit\" value=\"upload\">
</form>


When I submit I get this message:
Unable to open 'C:\\temp\\temp02.pdf' for reading:...

Where do the double-slashes come from? I didn´t had this before. The small and very primitive script (only uploading without passthru() to a 777-directory) works, but I copied exactly this code to the script which adds a bit of mysql after the upload has been done.

*confused*,
mazzo[/i]

Posted: Thu Aug 01, 2002 10:19 am
by Johnm
I am not sure where the slashes come from. I would try using the other functions that were recommended to see how they act. I am thinking that it is probably something else but let's eliminate the obvious first.



Direwolf

Posted: Fri Aug 02, 2002 3:54 am
by mazzogeddon
I have still trouble with the chmods...

I have tried the following
system("chmod 0777 test", $a1);
exec("chmod 0777 test", $a2[], $a21);
passthru("chmod 0777 test", $a3);


The script executed is in the directory in which 'test' is.

In all cases I get '1' as return value. That means that nothing has changed. The directory 'test' has still the same chmods (755 instead of 777).

What is my mistake?

Posted: Fri Aug 02, 2002 5:56 am
by mazzogeddon
I think it is a problem which is caused by my providers webserver configuration. something as
system("ls -l", $result)
works fine. But the chmod does not have any affect...
So I have finally given the chmods by ftp and the script works. I need stripslashes() to get rid of those doubleslashes in the filename.
And the Norton-Internet-Scurity did also disturb the process... better turn it off during those uploads.