0
所以我試圖使用cURL將文件發送到另一個頁面以及其他POST變量。除文件發送外,其中大部分都有效。但它只在我的本地主機上不起作用。當它上傳到託管的Web服務器時,它的工作原理與它應該完全相同。使用cURL發佈文件在路徑的開始處無法使用@
我也不想使用CURLFile,因爲Web服務器不支持它。
下面是代碼:
// Output the image
imagejpeg($fileData['imageBackground'], $newFileName, 75);
// Get Old Background
$query['getBackground'] = $this->PDO->prepare("SELECT backgroundImage FROM accounts WHERE token = :token");
$query['getBackground']->execute(array(':token' => $token));
$queryData = $query['getBackground']->fetch(PDO::FETCH_ASSOC);
$verificationKey = self::newVerificationKey($token);
// Send the file to the remote
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uploadURL);
curl_setopt($ch, CURLOPT_POST, true);
$postArgs = array(
'action' => 'updateBackground',
'verificationKey' => $verificationKey,
'file' => '@' . realpath($newFileName),
'oldBackground' => $queryData['backgroundImage']
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postArgs);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
unlink($newFileName);
提前感謝!
工作就像一個魅力。我只是完成了整個class_exists的方式,並且它完美地工作。謝謝! – Joaquim