2016-06-09 47 views
-1

我想做一個腳本來獲取一個可下載的文件,並將其放到我的FTP服務器,然後更新數據庫。我無法弄清楚這個網址的延伸應該是什麼樣的。試圖找到隱藏的下載URL上的文件擴展名

<?php 
$src = fopen('https://www.atf.gov/firearms/docs/0516-ffl-listxlsx/download', 'r'); 
$dest1 = fopen('first1k.xlsx', 'w'); 
$dest2 = fopen('remainder.xlsx', 'w'); 

echo stream_copy_to_stream($src, $dest1, 19759460) . " bytes copied to first1k.txt\n"; 
echo stream_copy_to_stream($src, $dest2) . " bytes copied to remainder.txt\n"; 

?> 

這是我想從https://www.atf.gov/firearms/listing-federal-firearms-licensees-ffls-2016

+1

獲取數據爲什麼不'file_get_contents'或捲曲? – ceejayoz

回答

0
<?php 
$file = "0516.xlsx"; 
$url = 'https://www.atf.gov/firearms/docs/0516-ffl-listxlsx/download' ; 

$handle = fopen("0516.xlsx", "w+"); 
fwrite($handle, file_get_contents($url)); 
rewind($handle); 

$read = htmlentities(fread($handle, filesize($file))); 

?> 

固定它