-1

I want download this link with PHP and save to folder it's a xlsx file

http://www.tsetmc.com/tsev2/excel/MarketWatchPlus.aspx?d=0

I use flower cods bout it's not true.

file_put_contents('A.xlsx', file_get_contents('http://www.tsetmc.com/tsev2/excel/MarketWatchPlus.aspx?d=0')); 
Cjmarkham
  • 9,484
  • 5
  • 48
  • 81

1 Answers1

0

Here's a recursive version.

function saveExternal($source,$local){
  $s = file_get_contents($source);
  $f = fopen($local,'w+');
  fwrite($f,$s);
  fclose($f);
}
saveExternal('http://www.tsetmc.com/tsev2/excel/MarketWatchPlus.aspx?d=0','A.xlsx');
Casey Dwayne
  • 2,142
  • 1
  • 17
  • 32
  • tanks, This code was downloaded but will not open the file A.xlsx – user3262996 Feb 02 '14 at 15:15
  • Hmm.. tried several different methods and the file keeps coming back as corrupt or empty. Good luck! May have something to do with the language, you may have to find the right mix of headers and use `readfile`. http://stackoverflow.com/questions/3938534/download-file-to-server-from-url http://stackoverflow.com/questions/13938190/php-force-downloading-xlsx-file-corrupt https://www.google.com/search?q=header+type+xlsx&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a – Casey Dwayne Feb 02 '14 at 15:35
  • I could not do something, you get me? – user3262996 Feb 02 '14 at 16:00
  • @user3262996 I tried. It's a very specific answer you seek and I do not know it. I attached several good leads to pursue. – Casey Dwayne Feb 02 '14 at 16:00