Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
chmod folders inside a folder
Old 07-21-2006, 01:23 PM chmod folders inside a folder
XRS
Experienced Talker

Posts: 32
Trades: 0
Hello.
I'm new here so I hope that this is the right place to post.

I have a script, to host images for the users.
That script, creates a folder inside the "/links" folder, so, it will be something like this:

"/links/xxxx
links/something"

and so on.

But theres a problem, the folders that the script automatically creates the folders with 777 permission, so, it won't be able to view for the users who share them. The folders must be in 755

I was in the php site, and found the chmod function.

It works something like this chmod ("dir", 755);

But this only chmod a directory.
How do I to chmod all the folders to 755 inside the /links folder with php code.

Note that I want this in PHP because the user makes the upload and it chmod the folder to 755 automatically.

I'm a kind of noob, so please explain it slowly :P

One more thing, sorry my bad english
XRS is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-21-2006, 02:10 PM Re: chmod folders inside a folder
AliKat's Avatar
Extreme Talker

Latest Blog Post:
Save the Children
Posts: 176
Location: MS
Trades: 0
Quote:
Originally Posted by PHP.net
Nicolas Merlet - admin(at)merletn.org
22-Jan-2006 08:34
Here is a very similar function to *scandir*, if you are still using PHP4...

This recursive function will return an indexed array containing all directories or files or both (depending on parameters). You can specify the depth you want, as explained below.

PHP Code:
<?php

// $path : path to browse
// $maxdepth : how deep to browse (-1=unlimited)
// $mode : "FULL"|"DIRS"|"FILES"
// $d : must not be defined
 
function searchdir $path $maxdepth = -$mode "FULL" $d )
{
   if ( 
substr $path strlen $path ) - ) != '/' ) { $path .= '/' ; }     
   
$dirlist = array () ;
   if ( 
$mode != "FILES" ) { $dirlist[] = $path ; }
   if ( 
$handle opendir $path ) )
   {
       while ( 
false !== ( $file readdir $handle ) ) )
       {
           if ( 
$file != '.' && $file != '..' )
           {
               
$file $path $file ;
               if ( ! 
is_dir $file ) ) { if ( $mode != "DIRS" ) { $dirlist[] = $file ; } }
               elseif ( 
$d >=&& ($d $maxdepth || $maxdepth 0) )
               {
                   
$result searchdir $file '/' $maxdepth $mode $d ) ;
                   
$dirlist array_merge $dirlist $result ) ;
               }
       }
       }
       
closedir $handle ) ;
   }
   if ( 
$d == ) { natcasesort $dirlist ) ; }
   return ( 
$dirlist ) ;
}
?>
Then use a foreach on the array returned with the chmod. Now I don't know exactly how the function returns the information as I just looked up the directory commands php.net. And this was an added comment.
AliKat is offline
Reply With Quote
View Public Profile Visit AliKat's homepage!
 
Old 07-21-2006, 03:14 PM Re: chmod folders inside a folder
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
In the actual function that creates the directory, you can define the mode.

mkdir('dir', 0755);
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 07-21-2006, 08:50 PM Re: chmod folders inside a folder
XRS
Experienced Talker

Posts: 32
Trades: 0
Well, the problem is that I just cant find where is the place where he creates the directory, i just cant find it because its a pre-made script.

And I can't understand how to use the foreach function after...
As I said, I'm a completly noob in PHP.
XRS is offline
Reply With Quote
View Public Profile
 
Old 07-21-2006, 08:56 PM Re: chmod folders inside a folder
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Is it a script you could post?
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 07-22-2006, 08:38 AM Re: chmod folders inside a folder
XRS
Experienced Talker

Posts: 32
Trades: 0
No, sorry.
It's a paid script.

But I solved the problem.
I read the whole file and found the right place to put the settings.

Thanks both.

Last edited by XRS; 07-22-2006 at 08:51 AM..
XRS is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to chmod folders inside a folder
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.39698 seconds with 12 queries