[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

How to change the existing folder chmod into 777 using php

I am copy a folder from one domain to another. For example domain A into domain B. All  Files and folders in the Domain A has 777 permission .But  After copied folders in the Domain B has only 755 permission.How to i change the permission of the folders in the domain B For copying the folder i am using this code

                                                $sourceDir = "contents/";

                                    $targetDir = "../../".$user_name;
                         
                                     copy_directory($sourceDir, $targetDir);

function copy_directory($source, $destination)

                        {
                                    if (is_dir($source))
                                    {
                                                $dir = opendir($source);
                                                @mkdir($destination);
                                                while(false !== ($file = readdir($dir)))
                                                {
                                                            if (( $file != '.' ) && ( $file != '..' ))
                                                            {
                                                                  if (is_dir($source.'/'.$file))
                                                                  {
                                                                                                                                                                                                    copy_directory($source.'/'.$file, $destination.'/'.$file);
                                                                  }
                                                                  else
                                                                  {
                                                      copy($source.'/'.$file, $destination.'/'.$file);
                                                                  }
                                                            }
                                                }
                                                
                                                            closedir($dir);
                                                                 else
                                    {
                                                copy($source, $destination);
                                    }
                        }


 this code copied the folder with the 755 permission ,
If i change the code like this it gives error
                                                              copy($source.'/'.$file, $destination.'/'.$file);
                                                chmod($destination.'/'.$file, 0777);

Warning: chmod() [function.chmod]: No such file or directory in /home/nsfg/public_html/videocode/viewpend.php on line 273.

Please guide me . thanks
                                     
                              
0
whspider
Asked:
whspider
3 Solutions
 
Dave BaldwinFixer of ProblemsCommented:
Do you have the Suhosin security patch in your PHP?  In another question, it seemed that that prevents setting any file in the web directory to '0777' with PHP.
0
 
Ray PaseurCommented:
whspider, while you are developing software you need to do a couple of things to help understand what your code is doing.

First, add these two statements to the top of your script: ini_set('display_errors', TRUE); error_reporting(E_ALL);
Next, lose the at-sign.  This kind of construct  @mkdir($destination); suppresses the error messages that you really need to see.
Next, adopt a coding standard that provides consistent alignment of control structures.  It will immediately reduce your error rate.
Finally, add comments (in fact, write the comments first, before you write any code) to help keep your thinking clear and to help others understand the code.

You might also want to try using the PHP constant DIRECTORY_SEPARATOR instead of hard-coded '/' because the constant will be context aware and the slash will not.

A warning that says, "No such file or directory in /home/nsfg/public_html/videocode/viewpend.php on line 273." is pretty clear.  Have you used some kind of FTP visualization to see if the referenced file actually exists?
0
 
requeueCommented:
I hope you can drill down where is the problem by following code:

if (copy($source.'/'.$file, $destination.'/'.$file))
{
    print("copy succeeded");
    print("source: " . $source.'/'.$file. "\n");
    print("dest  : " . $destination.'/'.$file. "\n");
    chmod($destination.'/'.$file, 0777);
}
else
{
    print("copy failed");
    print("source: " . $source.'/'.$file. "\n");
    print("dest  : " . $destination.'/'.$file. "\n");
}

Open in new window

0
 
whspiderAuthor Commented:
ok
0
 
CWS (haripriya)Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now