我正在使用此捲曲腳本嘗試通過FTP上傳用戶選擇的文件。它將文件上傳到服務器,但它們都是空白的。這是爲什麼發生?CURL通過FTP上傳空白文件
if (!empty($_FILES['userfile']['name'])) {
$ch = curl_init();
$localfile = $_FILES['upload']['tmp_name'];
$fp = fopen($localfile, 'r');
curl_setopt($ch, CURLOPT_URL, 'ftp-addy-here'.$_FILES['userfile']['name']);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_exec ($ch);
$error_no = curl_errno($ch);
curl_close ($ch);
if ($error_no == 0) {
$error = 'File uploaded succesfully.';
} else {
$error = 'File upload error.';
}
} else {
$error = 'Please select a file.';
}
echo $error;
刪除了html5標記,因爲它不相關。 –