使用 fopen 在文件名上加上问号
Question mark on filename using fopen
我在使用 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);
}
此脚本 returns 以下内容(我隐藏了实际地址 - 保留空格等):
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?
当我删除 ?我可以正常检索它并打开它。
这是什么?还有怎么才能不加到最后呢?
你用来命名文件的字符串末尾有一个不可打印的字符,而 ls
告诉你那里有 something,即使您通常无法看到它。在使用之前从字符串中删除字符。
我在使用 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);
}
此脚本 returns 以下内容(我隐藏了实际地址 - 保留空格等):
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?
当我删除 ?我可以正常检索它并打开它。 这是什么?还有怎么才能不加到最后呢?
你用来命名文件的字符串末尾有一个不可打印的字符,而 ls
告诉你那里有 something,即使您通常无法看到它。在使用之前从字符串中删除字符。