1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Copy files from remote server

Discussion in 'PHP' started by yourwish, May 6, 2016.

  1. #1
    I am trying to copy 5 files from server using a loop. I am getting last file only. First four are blank.

    
    //...
    while($row = mysql_fetch_array($result)){
            file_put_contents("folder/$row[ordid].pdf", file_get_contents($row[inv_link])); 
    //$row[inv_link] have remote file url http://www.example.com/file1.pdf
    
    PHP:
    I also tried copy function same results. Why first 4 files missing? Please help
     
    yourwish, May 6, 2016 IP
  2. hdewantara

    hdewantara Well-Known Member

    Messages:
    536
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #2
    Echo it first?
    
    while($row = mysql_fetch_array($result)){
            echo "folder/$row[ordid].pdf", ' from ', $row[inv_link]), PHP_EOL;
            //...
    
    Code (markup):
     
    hdewantara, May 6, 2016 IP
  3. yourwish

    yourwish Active Member

    Messages:
    43
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    98
    #3
    yourwish, May 6, 2016 IP
  4. hdewantara

    hdewantara Well-Known Member

    Messages:
    536
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #4
    Umm,
    I thought it was caused by file_put_contents() which overwrites files when used with no setting. Sorry man I have no idea why. Any warnings / errors from server log?
     
    hdewantara, May 6, 2016 IP
  5. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #5
    ThePHPMaster, May 6, 2016 IP
  6. Blizzardofozz

    Blizzardofozz Well-Known Member

    Messages:
    132
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    118
    #6
    I'm not getting the whole picture but try creating an array and fill in the elements within this loop. May be you getting only last file because you assigning to a string variable in the loop and in this case only last string is assigned to the variable. Or in some other loop this happens.
     
    Blizzardofozz, May 9, 2016 IP
  7. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #7
    Many be the file that you see was first written, and later folder doesn't have permissions to write. Please check the folder you are trying to write has CHMOD 777 permissions if it is a linux server. Or, we try debugging and helping you other possible ways.


    Stay well....
     
    Vooler, May 13, 2016 IP