Solved

How to change the existing folder chmod into 777 using php

Posted on 2011-02-13
6
286 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
6 Comments
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 168 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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 166 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 166 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now