Solved

How to change the existing folder chmod into 777 using php

Posted on 2011-02-13
6
323 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 83

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 110

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

690 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