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

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

Post Reply
mazzogeddon
Forum Newbie
Posts: 7
Joined: Thu Aug 01, 2002 7:23 am
Location: Berlin

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

Post 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
User avatar
Toneboy
Forum Contributor
Posts: 102
Joined: Wed Jul 31, 2002 5:59 am
Location: Law, Scotland.
Contact:

Post by Toneboy »

Erm, can't you do it through your FTP client? (Guessing, just learning this myself)
mazzogeddon
Forum Newbie
Posts: 7
Joined: Thu Aug 01, 2002 7:23 am
Location: Berlin

Post 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.
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post 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
mazzogeddon
Forum Newbie
Posts: 7
Joined: Thu Aug 01, 2002 7:23 am
Location: Berlin

Post by mazzogeddon »

OK, but are there no functions to change the rights of an directory by PHP?
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

Look up the function:
system()

Direwolf
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Was just going to say that but was a little slow. There's also exec() though.

Mac
mazzogeddon
Forum Newbie
Posts: 7
Joined: Thu Aug 01, 2002 7:23 am
Location: Berlin

Post 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]
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post 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
mazzogeddon
Forum Newbie
Posts: 7
Joined: Thu Aug 01, 2002 7:23 am
Location: Berlin

Post 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?
mazzogeddon
Forum Newbie
Posts: 7
Joined: Thu Aug 01, 2002 7:23 am
Location: Berlin

Post 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.
Post Reply