【发布时间】:2012-03-15 19:30:41
【问题描述】:
我需要在使用 php cURL 下载后重命名文件。
这是我所拥有的:
$localFile = fopen($fileName, 'w');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FILE, $localFile);
curl_setopt($curl, CURLOPT_USERPWD, "$ftpUsername:$ftpPassword");
curl_setopt($curl, CURLOPT_POSTQUOTE, array("RNFR $remoteFile", "RNTO $remoteFile.downloaded"));
curl_exec($curl) === false) {
throw new Exception(curl_error($curl));
}
如果我删除 CURLOPT_POSTQUOTE 部分,文件下载正常。我还尝试了后引用数组的几种不同组合:
curl_setopt($curl, CURLOPT_POSTQUOTE, array("RNFR $remoteFile RNTO $remoteFile.downloaded"));
curl_setopt($curl, CURLOPT_POSTQUOTE, array("-RNFR $remoteFile", "-RNTO $remoteFile.downloaded"));
curl_setopt($curl, CURLOPT_POSTQUOTE, array("-RNFR $remoteFile -RNTO $remoteFile.downloaded"));
curl_setopt($curl, CURLOPT_POSTQUOTE, array("rename $remoteFile $remoteFile.downloaded"));
我得到的错误看起来像:
ERROR : QUOT string not accepted: -RNFR $remoteFile -RNTO $remoteFile.downloaded
【问题讨论】: