从网址下载自动zip

时间:2014-06-21 09:07:55

标签: php mysql zip

我需要帮助我准备爆炸的一段代码,包含一个自动下载的外部URL zip文件夹,只包含一个txt文件,我将上传到mysql数据库,完成一个项目I&已经工作了五年。

简短版本是我需要从此网址获取每日文本文件:

http://batstrading.com/market_data/shortsales/2014/06/BYXXshvol20140620.txt.zip-dl?mkt=byx

我已经尝试了一切,一百种组合。在这些情况下没有发生错误,没有创建txt文件也没有上传到数据库,权限设置为777

zip_open,zip_read,zip_entry_open,zip_entry_read,fgets,fopens,file_get_contents

带有效网址的长版本是:

function getBATStxtfile($BATSzipurlFile, $BATSZoutputFile)
{  
    $BATSzipurl="http://batstrading.com/market_data/shortsales/2014/06/BYXXshvol20140620.txt.zip-dl?mkt=byx";  

    file_get_contents($BATSzipurl); 

    $batstxtzipFile=zip_open($BATSzipurl);  
    $batstxtzipFile=zip_read($BATSzipurl);  
    $batstxtFile = zip_entry_open($batstxtzipFile;  
    $batstxt = zip_entry_read($batstxtFile);  
    $batstxt = str_replace("Date|Symbol|Short Volume|Total Volume|Market Center", "",$batstxt);  
    $batstxt = str_replace("|",  ",", $batstxt);  
    $batstxt = trim($batstxt);  

    file_put_contents($BATSZoutputFile, $batstxt);

    zip_entry_close($batstxtFile);  
    zip_close($BATSzipurl);  
}

我有300万行代码,10,000个失败的脚本,而且我需要恢复生命...这个.txt文件被检索到了。先感谢您。

1 个答案:

答案 0 :(得分:0)

你去吧

<?php

// fetch zip file
$zip = file_get_contents('http://batstrading.com/market_data/shortsales/2014/06/BYXXshvol20140620.txt.zip-dl?mkt=byx');
file_put_contents('bats.zip', $zip);

// read specific file from zip archive
$txt = file_get_contents('zip://bats.zip#BYXXshvol20140620.txt');

// do text transformations
$txt = str_replace('Date|Symbol|Short Volume|Total Volume|Market Center', '', $txt);
$txt = str_replace('|',  ',', $txt);
$txt = trim($txt);

// output the modified txt to file
file_put_contents('out.txt', $txt);
相关问题