1

我正在尝试使用 将图像上传到服务器php curl_setopt,但我总是403 Forbidden在我包含base64_encode($image_data)但没有它时会成功发布。我也试图改变我的php.in,但仍然没有。之前一切正常,直到我在我的centos服务器中重新安装新操作系统,我真的不知道原因。

我的 PHP.INI

memory_limit=512M
upload_max_filesize=12M
post_max_size=128M
max_execution_time=60
max_input_vars=4000
#session.save_path=\\
session.save_path="/sessions_tmp"
magic_quotes_gpc=Off
session.gc_maxlifetime=365 * 24 * 60 * 60
session.cookie_lifetime=365 * 24 * 60 * 60
session.gc_divisor=1
session.gc_probability=1

我的 PHP 上传

if(($fileHandle = fopen($_FILES['image']['tmp_name'], "r"))){
$data = fread($fileHandle, filesize($_FILES['image']['tmp_name']));
$postVar  = array(
  /*This will work but using $data won't work
   'image' => base64_encode("UploadTest"),*/
  'image' => base64_encode($data), 
  'product_id' => '1020039393',
  'image_name' => 'tempCarImage.png',
  'file_name' => "CarImage",
  'upload' => 'GALLERY',
  'tag' => 1,
  'extension' => 'png',
  'chef_key' => 'M573Hakd'
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://example.com/assets/upload.php");
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . upload_cdn_server_key));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_ENCODING, '');
curl_setopt($curl, CURLOPT_POSTFIELDS, $postVar);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$out = curl_exec($curl);
$err = curl_error($curl);
curl_close ($curl);
fclose($fileHandle);
$pms = json_decode($out,true);
}

请任何人帮助我,我真的不知道是什么导致了这个问题。

4

0 回答 0