I want to use PHP to import files

Discussion in 'PHP' started by locpicker, Jul 17, 2009.

  1. #1
    Does anyone know how to use php to import a complete file and save it to the server that it is running on?
     
    locpicker, Jul 17, 2009 IP
  2. neegeris

    neegeris Banned

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    neegeris, Jul 17, 2009 IP
  3. locpicker

    locpicker Well-Known Member

    Messages:
    789
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    160
    #3
    What I am actually wanting to do is import zip files with php from a different server. More like a transload.
     
    locpicker, Jul 17, 2009 IP
  4. neegeris

    neegeris Banned

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you can download files from ftp using php, or you can donwload files if second server have php too..
     
    neegeris, Jul 17, 2009 IP
  5. locpicker

    locpicker Well-Known Member

    Messages:
    789
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    160
    #5
    I do not need to download. I need to copy from one server to another. I have tried a small script that uses the copy command but it will not get the file that I want. I am trying to import the clickbank xml zip file and just cannot figure out how to do it.
     
    locpicker, Jul 18, 2009 IP
  6. wrxbuzz

    wrxbuzz Peon

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    PM me the URL of the file and I'll show you how to do it.
     
    wrxbuzz, Jul 18, 2009 IP
  7. wrxbuzz

    wrxbuzz Peon

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Here's the working script, enjoy!

     
    wrxbuzz, Jul 18, 2009 IP
    locpicker likes this.
  8. locpicker

    locpicker Well-Known Member

    Messages:
    789
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    160
    #8
    I was beginning to think this was not possible. Thanks.

    Can you explain how it works?

    I am supposing that 8192 is the port?
     
    locpicker, Jul 18, 2009 IP
  9. Chemo

    Chemo Peon

    Messages:
    146
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #9
    
    <?php
    $remoteFile = "http://www.domain.com/something.zip";
    $localFile = basename($remoteFile);
    
    if ( false === file_put_contents($localFile, file_get_contents($remoteFile)) ){
        throw new RuntimeException("Could not save file");
    }
    ?>
    
    PHP:
     
    Chemo, Jul 19, 2009 IP
  10. wrxbuzz

    wrxbuzz Peon

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    You can use Chemo's code file_get_contents($remoteFile) , 8192 is the file size, not the port.
     
    wrxbuzz, Jul 19, 2009 IP
  11. locpicker

    locpicker Well-Known Member

    Messages:
    789
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    160
    #11
    I will try Chemo's version tomorrow. I think I can still use the other one as well.

    Is there anyway you can set the file size as a variable and let php fill it in?
     
    locpicker, Jul 19, 2009 IP