Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: PHP copy() function

  1. #11
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I think the issue is back to what Twey said originally:
    1. When you are copying it the CHMOD permissions are disabling it's execution (make it '777').
    2. Perhaps the actual data is not being transferred properly-- so be sure the text always shows up properly in the file once copied, and perhaps check things like character encoding if that for some odd reason might cause a problem.

    The other test here is to copy a file that is not included, then run that independently. If that runs, but the included version does not, then the inclusion is the issue, not the copying. Of course if it does copy and then doesn't run it's the copying that is a problem.

    I hope this points you in the right direction. Sounds like a strange problem.

    Also, having used the copy function a couple times, I found it useful to look at the comments and code suggestions below it on the php.net page, and there are a few things (like copying a directory recursively) that are helpful and might help with your problem, such as showing you how to copy with correct permissions (assuming that's an issue, someone else must have run into it before).
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  2. #12
    Join Date
    Jan 2009
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hi djr33,

    Thanks for the help, the code I'm using is:

    PHP Code:
    $source_file '../products/template.php';
    $dest_file '../products/' . @$_POST['product_code'] . '.php';
    copy($source_file,$dest_file);
    chmod ($dest_file0777); 
    The chmod seems to work fine and the file attributes show up in my FTP client as:

    -rwxrwxrwx (which is 777 as far as I'm aware?)

    As for the code inside the actual file, that is 100% in tact. I've downloaded the copied file (/products/testprod1.php in this case) and it's contents are exactly the same as the template file which it is a copy of.

    I'll have a look at character encoding and also take a look at the php.net site to see if that has any answers, thanks for the suggestions!

    On an aside, another related problem, I *was* trying to create a directory for the products ( ie. www.mydomain.com/products/testprod1/) and store all images and the actual product info in there, I can create the directory fine using:

    PHP Code:
    mkdir("../products/" $product_code0777); 
    However, I can't copy files into it (howeverI can save image files through a file upload into this newly created directory)... which leads me to believe both these problems are some kind of permission problem?

    Ta,

    Stu

  3. #13
    Join Date
    Jan 2009
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    ok, I've just gone through line by line and debugged the file, and it's just the 'include' functions that aren't working.

    Does anyone have any idea why copying a file using the PHP copy() function would case the file to just plain skip over any lines of code that use the include function?

    The reason absolutely nothing was displaying was because the way I was handling a mysql error. There is a line of:

    PHP Code:
    include 'config.php'
    which wasn't being 'included', and this was obviously causing any sql queries not to run.

    Anyone have any ideas why no includes at all are running when this php file is copied? But all other php commands work fine?!

    *pulls hair out!*

    Twey, you said originally,

    Of course the footer isn't being shown
    Is there something I'm totally missing?

    Thanks

    Stu

  4. #14
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    So it's the include functions within the copied page, or including those copied pages, or both?

    Also, does it work on a reload-- perhaps for some reason it only fails in the same execution in which it is created. That might give more information.

    I agree that it seems it has to do with a permission error, but I'm not sure what (include and copy are allowed individually, but not together?), which leads me to think it may be a bug, not a lack of permission.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #15
    Join Date
    Jan 2009
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    It's the 'include' functions within the copied page that are not working at all, it's just skipping over them, so everything that should be 'included' inside the copied file, isn't!

    The pages that are meant to be included are fine. I've tried reloading the copied page, but that doesn't help. Downloading it, deleting it off the server, and then uploading it does, however, make it work.

    I hope I've explained that ok!

    Thanks,

    Stu

  6. #16
    Join Date
    Jan 2009
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    ok, I'm getting there... slowly! The problem is a permission problem, how do I get round the following error:

    Code:
    Warning: main() [function.main]: SAFE MODE Restriction in effect. The script whose uid is 48 is not allowed to access ../admin/config.php owned by uid 10024 in /var/www/vhosts/lynchfordaquatics.co.uk/httpdocs/newsite/products/testprod3.php on line 7
    
    Warning: main(../admin/config.php) [function.main]: failed to open stream: No such file or directory in /var/www/vhosts/lynchfordaquatics.co.uk/httpdocs/newsite/products/testprod3.php on line 7
    
    Warning: main() [function.include]: Failed opening '../admin/config.php' for inclusion (include_path='.:') in /var/www/vhosts/lynchfordaquatics.co.uk/httpdocs/newsite/products/testprod3.php on line 7
    Why oh why doesn't it have permission to access the other config file?!

    Stu

  7. #17
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Because they are owned by different users. Probably your files have a special 'web user', named 'nobody' or 'www-data'. You need to chown the files to the user who owns the rest of your files.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. The Following User Says Thank You to Twey For This Useful Post:

    stu2000 (01-21-2009)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •