ill*_*ois 2 php copy file php-stream-wrappers
我在复制文件时遇到问题.我的代码:
$file = "https://www.ilportaleofferte.it/portaleOfferte/resources/opendata/csv/offerteML/2019_1/PO_Offerte_G_MLIBERO_20190130.xml";
$newfile = $_SERVER['DOCUMENT_ROOT'] . '/input/PO_Offerte_G_MLIBERO_20190130.xml';
if(copy($file, $newfile)) {
echo "salvato<br>";
} else {
echo "ERROR inport file PO_Offerte_".$data.".".$ext."<br>";
die;
}
Run Code Online (Sandbox Code Playgroud)
copy() 如果是,则创建文件但文件末尾的某些行丢失...文件为3.6MB,文件末尾的0.3缺失...
如果我手动下载文件一切都很好,所以源完成...
如果我获得文件内容,我实际上有同样的问题file_get_contents(),我尝试使用文件写入功能将其保存在文件中...
我不认为upload_max_filesize并且post_max_size实际参与其中,copy()但它们是20MB设置
任何提示?
谢谢
我能够使用file_get_contents 和强制HTTP/1.1协议:
$context = stream_context_create([
'http' => [
'protocol_version' => '1.1',
'header' => 'Connection: Close'
],
]);
$content = file_get_contents('https://www.ilportaleofferte.it/portaleOfferte/resources/opendata/csv/offerteML/2019_1/PO_Offerte_G_MLIBERO_20190130.xml', false, $context);
file_put_contents('document.xml', $content);
Run Code Online (Sandbox Code Playgroud)
话虽如此,我建议使用CURL:
$ch = curl_init();
$curlopts = array();
$curlopts[CURLOPT_RETURNTRANSFER] = true;
$curlopts[CURLOPT_VERBOSE] = true;
$curlopts[CURLOPT_URL] = 'https://www.ilportaleofferte.it/portaleOfferte/resources/opendata/csv/offerteML/2019_1/PO_Offerte_G_MLIBERO_20190130.xml';
curl_setopt_array($ch, $curlopts);
$content = curl_exec($ch);
file_put_contents('document.xml', $content);
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
243 次 |
| 最近记录: |