Jump to content

help with dir/file modes


hobojjr

Recommended Posts

Hi,

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?
Link to comment
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]

[code=php:0]mkdir("yourdir");[/code]


[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
[code=php:0]
$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);
}[/code]

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,
Tom
Link to comment
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,
Tom
Link to comment
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.

edit----
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)


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.