?
Solved

How to change the existing folder chmod into 777 using php

Posted on 2011-02-13
6
Medium Priority
?
325 Views
Last Modified: 2013-11-27
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
Comment
Question by:whspider
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 672 total points
ID: 34885826
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
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 664 total points
ID: 34888272
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
 
LVL 2

Assisted Solution

by:requeue
requeue earned 664 total points
ID: 34888520
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
 

Author Comment

by:whspider
ID: 35180552
ok
0
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 39680213
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question