Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: How does copy() function work?

  1. #1
    Join Date
    Sep 2009
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default How does copy() function work?

    Hi,

    copy(source_file,target_file)

    Where should be the source file ?

    On client?

    On server?

    An URL on web?

    Can we solve this problem?

  2. #2
    Join Date
    Sep 2009
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    I think I got the solution :

    Before PHP Version 5.2.9 "the source file" could be placed on local computer or on remote server (on the web) or it could be URL on the web.

    The location of the source file doesn't make any difference if the server has the PHP Version older than 5.2.9. There will be no errors while uploading a file from the user's computer to the web server that the script is running on via a form enctyped as multipart/form-data.

    But in version 5.2.9 the source file can only be either a URL on the web or a path on remote server (on the web). Copy() function interprets the POSTed file path as a path on remote server on the web.

    If the above commitment is incorrect or missing some points please let me know.

    Nejat
    Last edited by psikolog; 09-02-2009 at 03:27 PM.

  3. #3
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Can be either one. For example ...

    PHP Code:
    copy("C:/Desktop/MyFile.txt""uploads/"); 
    -OR-

    PHP Code:
    copy("../files/MyFile.txt""uploads/"); 
    -OR-

    PHP Code:
    copy("/home/user/files/MyFile.txt""uploads/"); 
    For more info, see:
    http://php.net/copy
    - Josh

  4. The Following User Says Thank You to JShor For This Useful Post:

    psikolog (09-02-2009)

  5. #4
    Join Date
    Sep 2009
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    I know what www.php.net declares.

    But in version 5.2.9 user can't upload a file to the server via a form.

    I tested the code

    1. on my local server (on my computer) => it worked.

    2. on Yahoo server with version 4.3.11 => it worked.

    3. on another server with version 5.2.9 => it did not worked.

    Thank you. I will appreciate your comments.

    Nejat

  6. #5
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Right, like posted before, sounds to me like it's a configuration problem with the server. That happens. I'll google for you and tell you what I come up with.

    BTW, see:
    http://www.dynamicdrive.com/forums/s...8086&page=2#12
    - Josh

  7. #6
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Problem is, we don't know WHAT exactly is going on. This code may help you:

    PHP Code:
    <?php

    function file_upload_error_message($error_code) {
        switch (
    $error_code) {
            case 
    UPLOAD_ERR_INI_SIZE:
                return 
    'The uploaded file exceeds the upload_max_filesize directive in php.ini';
            case 
    UPLOAD_ERR_FORM_SIZE:
                return 
    'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
            case 
    UPLOAD_ERR_PARTIAL:
                return 
    'The uploaded file was only partially uploaded';
            case 
    UPLOAD_ERR_NO_FILE:
                return 
    'No file was uploaded';
            case 
    UPLOAD_ERR_NO_TMP_DIR:
                return 
    'Missing a temporary folder';
            case 
    UPLOAD_ERR_CANT_WRITE:
                return 
    'Failed to write file to disk';
            case 
    UPLOAD_ERR_EXTENSION:
                return 
    'File upload stopped by extension';
            default:
                return 
    'Unknown upload error';
        }
    }

    $dest "upload/";

    copy($_FILES['file'], $dest);

    // Example
    if ($_FILES['file']['error'] === UPLOAD_ERR_OK)
        
    // upload ok
    else
        
    $error_message file_upload_error_message($_FILES['file']['error']);

    ?>
    ... taken directly from:
    http://us3.php.net/manual/en/feature...oad.errors.php

    [that may or may not work. proofread the code]

    But point of that code will be, if it's a server problem, you'll either get case 6 or 8.
    - Josh

  8. #7
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    I think I found another possibility:
    http://us3.php.net/manual/en/feature...n-pitfalls.php

    IF the file is fairly large, there could be a timeout limit -OR- the server MAX_UPLOAD_SIZE is not letting you upload a file that big,

    Try uploading a really really tiny file, like a .txt file with nothing in it. If that fails, then this idea should be knocked off the board.
    - Josh

  9. #8
    Join Date
    Sep 2009
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    All php.ini values are ok, and my filesizes are between 1 kb and 17 kb.

    I also used the same file (3 kb) for all my tests.

    In fact before posting this issue I did a wide research (took my 3 days), I reached to an explanation but I could not solve it.

    Hoping to solve this problem alltogether.

    Thank you.

    Nejat

  10. #9
    Join Date
    Sep 2009
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    The error message is :

    Warning: copy(C:\\wamp\\www\\noyaevofis\\images\\block.png) [function.copy]: failed to open stream: No such file or directory in .........

    I think the server : "there is no path such 'C:\\wamp\\www\\noyaevofis\\images\\block.png' in my disk." says.

  11. #10
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Why don't you guys consolidate this to just one thread.

    There is definitely no path like this: C:\\wamp\\www\\noyaevofis\\images\\block.png

    Now what could be causing you to have two directory separtors instead of one? I do not know...

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
  •