Php curl You don't have permission to access the file when uploading image
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.
php curl httpforbiddenhandler
|
show 4 more comments
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.
php curl httpforbiddenhandler
does yourfread()
command succeed? Doesbase64_encode($data)
return a valid result? Do you have access to the source code ofhttps://example.com/assets/upload.php
(I realise that's not the real URL, but you get my point)? Perhaps that could tell you conditions in which it might decide to return a 403. Or perhaps the people who maintain it can tell you. Perhaps the data is too big, or something
– ADyson
Nov 14 '18 at 23:25
@ADyson yes thefread()
succeed and i have access to the file upload.php
– Peter
Nov 14 '18 at 23:27
ok then so in uploads.php is there any code where can decide to output a 403 response? If not then maybe it's happening at the webserver level. How big is the encoded data (i.e. the output ofbase64_encode($data)
)?
– ADyson
Nov 14 '18 at 23:27
btw, why does uploads.php not just accept a standard multi-part request instead of having to encode the file data? It's generally more efficient (as the documentation notes, base64-encoding makes it 33% or so larger) and you don't have to decode it at the other side.
– ADyson
Nov 14 '18 at 23:31
1
What I'm suggesting is that you use cURL to construct the same kind of request, and then that your "uploads.php" script on the remote server is re-designed to accept data in the standard way using $_FILES and $_POST. There's a fairly decent example of the curl code here: gist.github.com/maxivak/18fcac476a2f4ea02e5f80b303811d5f . There'a also a very simple example of a multi-part request body at the bottom of this page: developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
– ADyson
Nov 15 '18 at 9:31
|
show 4 more comments
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.
php curl httpforbiddenhandler
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.
php curl httpforbiddenhandler
php curl httpforbiddenhandler
asked Nov 14 '18 at 22:30
PeterPeter
201211
201211
does yourfread()
command succeed? Doesbase64_encode($data)
return a valid result? Do you have access to the source code ofhttps://example.com/assets/upload.php
(I realise that's not the real URL, but you get my point)? Perhaps that could tell you conditions in which it might decide to return a 403. Or perhaps the people who maintain it can tell you. Perhaps the data is too big, or something
– ADyson
Nov 14 '18 at 23:25
@ADyson yes thefread()
succeed and i have access to the file upload.php
– Peter
Nov 14 '18 at 23:27
ok then so in uploads.php is there any code where can decide to output a 403 response? If not then maybe it's happening at the webserver level. How big is the encoded data (i.e. the output ofbase64_encode($data)
)?
– ADyson
Nov 14 '18 at 23:27
btw, why does uploads.php not just accept a standard multi-part request instead of having to encode the file data? It's generally more efficient (as the documentation notes, base64-encoding makes it 33% or so larger) and you don't have to decode it at the other side.
– ADyson
Nov 14 '18 at 23:31
1
What I'm suggesting is that you use cURL to construct the same kind of request, and then that your "uploads.php" script on the remote server is re-designed to accept data in the standard way using $_FILES and $_POST. There's a fairly decent example of the curl code here: gist.github.com/maxivak/18fcac476a2f4ea02e5f80b303811d5f . There'a also a very simple example of a multi-part request body at the bottom of this page: developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
– ADyson
Nov 15 '18 at 9:31
|
show 4 more comments
does yourfread()
command succeed? Doesbase64_encode($data)
return a valid result? Do you have access to the source code ofhttps://example.com/assets/upload.php
(I realise that's not the real URL, but you get my point)? Perhaps that could tell you conditions in which it might decide to return a 403. Or perhaps the people who maintain it can tell you. Perhaps the data is too big, or something
– ADyson
Nov 14 '18 at 23:25
@ADyson yes thefread()
succeed and i have access to the file upload.php
– Peter
Nov 14 '18 at 23:27
ok then so in uploads.php is there any code where can decide to output a 403 response? If not then maybe it's happening at the webserver level. How big is the encoded data (i.e. the output ofbase64_encode($data)
)?
– ADyson
Nov 14 '18 at 23:27
btw, why does uploads.php not just accept a standard multi-part request instead of having to encode the file data? It's generally more efficient (as the documentation notes, base64-encoding makes it 33% or so larger) and you don't have to decode it at the other side.
– ADyson
Nov 14 '18 at 23:31
1
What I'm suggesting is that you use cURL to construct the same kind of request, and then that your "uploads.php" script on the remote server is re-designed to accept data in the standard way using $_FILES and $_POST. There's a fairly decent example of the curl code here: gist.github.com/maxivak/18fcac476a2f4ea02e5f80b303811d5f . There'a also a very simple example of a multi-part request body at the bottom of this page: developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
– ADyson
Nov 15 '18 at 9:31
does your
fread()
command succeed? Does base64_encode($data)
return a valid result? Do you have access to the source code of https://example.com/assets/upload.php
(I realise that's not the real URL, but you get my point)? Perhaps that could tell you conditions in which it might decide to return a 403. Or perhaps the people who maintain it can tell you. Perhaps the data is too big, or something– ADyson
Nov 14 '18 at 23:25
does your
fread()
command succeed? Does base64_encode($data)
return a valid result? Do you have access to the source code of https://example.com/assets/upload.php
(I realise that's not the real URL, but you get my point)? Perhaps that could tell you conditions in which it might decide to return a 403. Or perhaps the people who maintain it can tell you. Perhaps the data is too big, or something– ADyson
Nov 14 '18 at 23:25
@ADyson yes the
fread()
succeed and i have access to the file upload.php– Peter
Nov 14 '18 at 23:27
@ADyson yes the
fread()
succeed and i have access to the file upload.php– Peter
Nov 14 '18 at 23:27
ok then so in uploads.php is there any code where can decide to output a 403 response? If not then maybe it's happening at the webserver level. How big is the encoded data (i.e. the output of
base64_encode($data)
)?– ADyson
Nov 14 '18 at 23:27
ok then so in uploads.php is there any code where can decide to output a 403 response? If not then maybe it's happening at the webserver level. How big is the encoded data (i.e. the output of
base64_encode($data)
)?– ADyson
Nov 14 '18 at 23:27
btw, why does uploads.php not just accept a standard multi-part request instead of having to encode the file data? It's generally more efficient (as the documentation notes, base64-encoding makes it 33% or so larger) and you don't have to decode it at the other side.
– ADyson
Nov 14 '18 at 23:31
btw, why does uploads.php not just accept a standard multi-part request instead of having to encode the file data? It's generally more efficient (as the documentation notes, base64-encoding makes it 33% or so larger) and you don't have to decode it at the other side.
– ADyson
Nov 14 '18 at 23:31
1
1
What I'm suggesting is that you use cURL to construct the same kind of request, and then that your "uploads.php" script on the remote server is re-designed to accept data in the standard way using $_FILES and $_POST. There's a fairly decent example of the curl code here: gist.github.com/maxivak/18fcac476a2f4ea02e5f80b303811d5f . There'a also a very simple example of a multi-part request body at the bottom of this page: developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
– ADyson
Nov 15 '18 at 9:31
What I'm suggesting is that you use cURL to construct the same kind of request, and then that your "uploads.php" script on the remote server is re-designed to accept data in the standard way using $_FILES and $_POST. There's a fairly decent example of the curl code here: gist.github.com/maxivak/18fcac476a2f4ea02e5f80b303811d5f . There'a also a very simple example of a multi-part request body at the bottom of this page: developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
– ADyson
Nov 15 '18 at 9:31
|
show 4 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309705%2fphp-curl-you-dont-have-permission-to-access-the-file-when-uploading-image%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309705%2fphp-curl-you-dont-have-permission-to-access-the-file-when-uploading-image%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
does your
fread()
command succeed? Doesbase64_encode($data)
return a valid result? Do you have access to the source code ofhttps://example.com/assets/upload.php
(I realise that's not the real URL, but you get my point)? Perhaps that could tell you conditions in which it might decide to return a 403. Or perhaps the people who maintain it can tell you. Perhaps the data is too big, or something– ADyson
Nov 14 '18 at 23:25
@ADyson yes the
fread()
succeed and i have access to the file upload.php– Peter
Nov 14 '18 at 23:27
ok then so in uploads.php is there any code where can decide to output a 403 response? If not then maybe it's happening at the webserver level. How big is the encoded data (i.e. the output of
base64_encode($data)
)?– ADyson
Nov 14 '18 at 23:27
btw, why does uploads.php not just accept a standard multi-part request instead of having to encode the file data? It's generally more efficient (as the documentation notes, base64-encoding makes it 33% or so larger) and you don't have to decode it at the other side.
– ADyson
Nov 14 '18 at 23:31
1
What I'm suggesting is that you use cURL to construct the same kind of request, and then that your "uploads.php" script on the remote server is re-designed to accept data in the standard way using $_FILES and $_POST. There's a fairly decent example of the curl code here: gist.github.com/maxivak/18fcac476a2f4ea02e5f80b303811d5f . There'a also a very simple example of a multi-part request body at the bottom of this page: developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
– ADyson
Nov 15 '18 at 9:31