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
Echo it first? while($row = mysql_fetch_array($result)){ echo "folder/$row[ordid].pdf", ' from ', $row[inv_link]), PHP_EOL; //... Code (markup):
It will be like folder/93.pdf from http://www.example.com/file13d3fd.pdf folder/94.pdf from http://www.example.com/file6ry433a.pdf folder/95.pdf from http://www.example.com/file65442.pdf and so on...
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?
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.
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....