Php curl You don't have permission to access the file when uploading image

1.2k views Asked by At

Am trying to upload image to a server using php curl_setopt, but i always get 403 Forbidden whenever i include base64_encode($image_data) but without that it will post successfully. I have also tried to change my php.in, but still yet. Everything was working fine before, till i reinstall new os in my centos server, i don't really know the cause.

MY 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

MY PHP UPLOAD

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);
}

Please can anyone help me, i really don't know what is causing this problem.

0

There are 0 answers