[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to change the existing folder chmod into 777 using php

Posted on 2011-02-13
6
Medium Priority
?
331 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

650 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