【发布时间】:2016-09-14 05:38:40
【问题描述】:
我在使用 fopen 保存文件时遇到问题。由于某种原因,保存的文件最后有一个问号。
我正在尝试从远程服务器检索文件列表并将它们下载到我的服务器。 这是我完成这项工作的代码的一部分:
$arrlength = count($reports);
for ($x = 0; $x < $arrlength; ++$x) {
$report = $reports[$x];
$thefilepath = returnfilename($report);
echo 'the filepath : '.$thefilepath;
echo '<br>';
$thefilename = basename($thefilepath).PHP_EOL;
echo 'the filename : '.$thefilename;
echo '<br>';
$localfile = 'incoming/'.$thefilename;
echo 'local file to save : '.$localfile;
echo '<br>';
curl_setopt($ch, CURLOPT_URL, $thefilepath);
$out = curl_exec($ch);
$fp = fopen($localfile, 'w');
fwrite($fp, $out);
fclose($fp);
}
此脚本返回以下内容(我已隐藏实际地址 - 保留空格等):
the filepath : https://example.com.com/xxx/xxx.xlsx
the filename : xxx.xlsx
local file to save : incoming/xxx.xlsx
当我在我的服务器上执行 ls 时,我得到了:
-rw-r--r-- 1 www-data www-data 29408 May 17 23:01 xxx.xlsx?
文件没有问题,当我删除 ?我可以正常检索并打开它。 这是什么?我该怎么做才能让它最终不添加?
【问题讨论】:
-
尝试将随机字符复制粘贴到 Google 中,它应该会显示它是什么类型的字符,在它真的很烦人之前我已经遇到过这个问题:P