Jump to content


This topic is now archived and is closed to further replies.


help with dir/file modes

Recommended Posts


I am trying to do the following

1)new dir
2)copy existing files to new dir
3)upload some new files to the new dir
3)do something to the new files
4)delete copied files

At the end I want to end up with the new dir so that people can read it only. Can somone help me out with the file/folder mod permission for each step?

Share this post

Link to post
Share on other sites
Well first I would like to say welcome to phpfreaks!

Now lets see what I can do for you.

1:)You can create a new directory with the [url=http://us3.php.net/manual/en/function.mkdir.php]mkdir[/url] function. Now depending one the OS you may need to set a chmod. If you are using Windows then you do not need to specfi a chmod.

[b]For Windows[/b]


[b]For *nix[/b]

[code=php:0]mkdir("yourdir", 0700);[/code]
You may want to study up on [url=http://catcode.com/teachmod/]chmod[/url]

I normarly do something like this
$path = "path/to/dir";
$chmod = '';//what ever chmod that you want
if (is_dir($path . "/yourdir") == false) {//checks to see if the new directory already exits
   mkdir("yourdir", $chomd);

2:) Now you can go about this in a couple different ways. This depends on if you are wanting to copy all of the files in one directory or if you are wanting to just copy a few files to the new diretory(.i.e.. index.php or html).

If you are wanting to copy all files from a directory then you may want to look into [url=http://us3.php.net/manual/en/function.opendir.php]opendir[/url] and [url=http://us3.php.net/manual/en/function.readdir.php] readdir[/url]

Now ether way you will want to look into [url=http://us3.php.net/manual/en/function.fopen.php]fopen[/url], [url=http://us3.php.net/manual/en/function.fread.php]fread[/url] and [url=http://us3.php.net/manual/en/function.fwrite.php]fwrite[/url].

3:) You can check out this great tutorial for createing a [url=http://www.phpfreaks.com/tutorials/85/0.php]File Upload Class[/url]

4:)To delete a file you can use [url=http://us3.php.net/manual/en/function.unlink.php]unlink[/url] and for directorys [url=http://us3.php.net/manual/en/function.rmdir.php]rmdir[/url]

I hope this helps.

Good Luck,

Share this post

Link to post
Share on other sites
Thanks for the welcome and your reply.

I know how to write my script but I am not getting the result I want.
I need to know what permission to set for the folder and the scripts while going through the above mentioned stages.  ;D

Share this post

Link to post
Share on other sites
I am going to assume that you are using a *nix system. Now you have to be careful. I am not sure if your host has set you as a owner or in a group or what.  To be safe 0774 would allow read, write and execute access to the file/dir. Now I guess that you could play with this a bit.

Also, what ftp program are you using. You can set the chmod via ftp and it might be a bit easier. Check out [url=http://us3.php.net/manual/en/function.chmod.php]chmod[/url].

Good Luck,

Share this post

Link to post
Share on other sites
I need to do it with php script.
When I run my script I end up with a dir that I cannot delete it or the files inside.

the problem is, when I run the script and creat new dir and copy the files, I cannot delete the dir/files and I cannot change their mod from my ftp account.

I am hosted by yurx.com
----general server info----
Operating system  Linux
Service Status Click to View
Kernel version 2.6.9-22.ELsmp
Machine Type i686
Apache version 1.3.36 (Unix)
PERL version 5.8.7
Path to PERL /usr/bin/perl
Path to sendmail /usr/sbin/sendmail
Installed Perl Modules Click to View
PHP version 4.4.2
MySQL version 4.1.21-standard
cPanel Build 10.8.2-RELEASE 119
Theme cPanel X v2.5.0
Documentation Click to View
cPanel Pro 1.0 (RC36)

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.