I have been very frustrated in my attempt to send an image to an API using Curl. The image is coming from an html form from the clients end. When the form is submitted, I check to make sure the file is an image and the image is moved to an uploads folder as such:
$location = "ImageUploads/";
if(isset($_FILES["Image"]["tmp_name"]))
{
$checkImage = getimagesize($_FILES["Image"]["tmp_name"]);
if($checkImage !== false){
$Image = $_FILES['Image']['tmp_name'];
$ImageContent = addslashes(file_get_contents($Image));
$ImagePosted =true;
$ImageRealName = $_FILES['Image']['name'];
if(move_uploaded_file($Image, $location.$ImageRealName))
{
echo 'File Uploaded';
}
}
else{
echo 'Image not submitted';
}
After I move the image to an uploads folder, I initiate the curl Post as such:
$baseURL ="https://apithatIamusing.com/api/";
$curl = curl_init($baseURL);
$myImage = new CURLFile($location.$_FILES['Image']['name'],$_FILES['Image']['type'],$_FILES['Image']['name']);
After this, I create a curl_post_data array to include the rest of the api data requirements:
$curl_post_data = array(
'public_key' => $publicKey,
'private_key' => $privateKey,
'order_type' => 'Image',
'origin_id' => '11111111',
'name' => $FirstName,
'surname' => $LastName,
'photo' => $myImage);
I then set all of the Curtopts that I will be using:
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_UPLOAD, TRUE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
I then execute and attempt to decode the json response:
$imageResult= curl_exec($curl);
if($imageResult ===false)
{
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
$imageJson = json_decode($imageResult, true);
curl_close($curl);
$imageSuccess = $imageJson["success"];
$imageMessage = $imageJson["message"];
$imageSuccess = $imageJson["result"];
echo '<p>imageSuccess:'.$imageSuccess.' </p>';
echo '<p>imageMessage: '.$imageMessage.' </p>';
echo '<p>imageSuccess: '.$imageSuccess.' </p>';
I believe that the issue could be with the $myImage that curl is creating, the api documentation asks for the 'photo' to include the following information:
filename="t1.png"
Content-Type: image/png
But, to my understanding, curlfile is including, the name, content-type and the post name. Any recommendations or other methods to make this api post call using php would be greatly appreciated.
Related
I have a shell code as below."curl -X POST -F 'file=#textomate-api.pdf;type=text/plain' https://textomate.com/a/uploadMultiple"
This code send a file to the URL and get the response below.
{
"countedFiles": [
{
"wordsNumber": 340,
"charsNumber": 2908,
"charsNoSpacesNumber": 2506,
"wordsNumberNN": 312,
"charsNumberNN": 2755,
"charsNoSpacesNumberNN": 2353,
"md5": null,
"fileName": "textomate-api.pdf",
"error": null
}
],
"total": {
"wordsNumber": 340,
"charsNumber": 2908,
"charsNoSpacesNumber": 2506,
"wordsNumberNN": 312,
"charsNumberNN": 2755,
"charsNoSpacesNumberNN": 2353,
"md5": null
}
}
And I want to post a file via PHP and get this response or only value of "charsNoSpacesNumber".
Could you please help me with this?
Thanks a lot
You can do it as follows:
YET be sure to first check their T&C as I am not sure if they provide such a service for free.
Also be sure to include some error / exceptions handling.
<?php
//Initialise the cURL var
$ch = curl_init();
//Get the response from cURL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Set the Url
curl_setopt($ch, CURLOPT_URL, 'https://textomate.com/a/uploadMultiple');
$path = '/path/to/your/file.pdf';
$file = curl_file_create($path, 'application/pdf', 'file');
//Create a POST array with the file in it
$postData = array(
'file' => $file,
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
// Execute the request, decode the json into array
$response = json_decode(curl_exec($ch), true);
var_dump($response['total']['charsNoSpacesNumber']);
Thanks for your support Bartosz.
This is my code and I also shared an image of the code and results.
I hope there are enough information.
<?php
if(is_callable('curl_init')){
echo "curl is active";
} else {
echo "curl is passive";
}
//Initialise the cURL var
$ch = curl_init();
//Get the response from cURL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Set the Url
curl_setopt($ch, CURLOPT_URL, 'https://textomate.com/a/uploadMultiple');
$path = 'textomate-api.pdf';
$file = curl_file_create($path, 'application/pdf', 'file');
//Create a POST array with the file in it
$postData = array(
'file' => $file,
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
// Execute the request, decode the json into array
$response = json_decode(curl_exec($ch), true);
var_dump($response['total']['charsNoSpacesNumber']);
var_dump($response);
var_dump(file_exists($path));
?>
Updated code is below and you can see the results in the image.
I want to use this API on my website to be able to calculate character count of documents. I am using Wordpress and API provider gives us 3 options, Java, PHP (Wordpress) and Shell. They have something for Wordpress but I don't know how to use it.
You can reach all the files from here.
https://github.com/zentaly/textomate-api
If you take a look there, you can get more information and maybe you can find me a better solution.
And again thank you so much for your support, I appreciate it.
<?php
if(is_callable('curl_init')){
echo "curl is active";
} else {
echo "curl is passive";
}
//Initialise the cURL var
$ch = curl_init();
//Get the response from cURL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Set the Url
curl_setopt($ch, CURLOPT_URL, 'https://textomate.com/a/uploadMultiple');
curl_setopt($ch, CURLOPT_VERBOSE, 2);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec: var_dump(curl_errno($ch));
var_dump(curl_error($ch));
$path = 'textomate-api.pdf';
$file = curl_file_create($path, 'application/pdf', 'file');
//Create a POST array with the file in it
$postData = array(
'file' => $file,
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
// Execute the request, decode the json into array
$response = curl_exec($ch);
var_dump($response);
$response = json_decode($ch);
var_dump($response['total']['charsNoSpacesNumber']);
var_dump($response);
var_dump(file_exists($path));
var_dump($file);
?>
The main problem that i've to do is sending an image from another server to AWS after some process. For that i've done the database processes in the first server. It works very well, i tested it. After that i've to send this image directly to AWS to start another .php file. I try it via cURL function:
server1.php the php file that's found in the first server:
$url = 'http://myawsurl.com/server/test.php';
$imageData = file_get_contents($_FILES['fileToUpload']['tmp_name']);
$post_data = array(
'tmp' => $_FILES["fileToUpload"]["tmp_name"],
'type' => $_FILES["fileToUpload"]["type"],
'name' => $_FILES["fileToUpload"]["name"],
'data' => $imageData
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
print_r($output);
test.php the php file that's found in aws:
if ($_POST["tmp"] && $_POST["name"] && $_POST["type"] && $_POST["data"]) {
$target_dir_requests = "/requests/";
create_folder_if_not_exist(ABSPATH . $target_dir_requests);
$dir_for_req_server = ABSPATH . $target_dir_requests . basename($_FILES["fileToUpload"]["name"]);
$dir_for_req_server = base64_to_jpeg($_POST["data"],$dir_for_req_server);
// After some requests that i've to do and i've done
} else {
echo "data sending error";
}
i tried something for todo but they did not work. Could you please help me for find a solution ? Thanks.
You are checking if the variable is true or not with the if($_POST[])
What you actually want is to check if the variable isset
Try this and see if you get any result:
if(isset($_POST['tmp'])){
echo 'test';
}
Or
$tmp = isset($_POST['tmp']) ? trim($_POST['tmp']) : null;
if(!empty($tmp)){
echo 'test';
}
The curl itself should be working
I've been trying to upload a file to a remote API via CURL for the past few days with little luck, The code works perfectly on windows, and I get the desired returned output back from the API.
My issue is that once I move to a linux environment and I upload the file via CURL I get the error message below.
What I tried:
I thought perhaps permissions and the likes were the cause of my problem as it was saying that it cannot find the file, so I decided to modify my code slightly to upload to the server, move it into an upload folder then pick that file to send via curlfile but still no luck. Here is the error I'm getting:
"errors": [
{
"developerMessage": "Error while manipulating file /home/USER/public_html/top/tmp/client17.jpg due to a File system / Amazon S3 issue /usr/share/tomcat7/.fineract/top/documents/clients/1/8q9sr/home/USER/public_html/top/tmp/client17.jpg (No such file or directory)",
"defaultUserMessage": "Error while manipulating file /home/USER/public_html/top/tmp/client17.jpg due to a File system / Amazon S3 issue /usr/share/tomcat7/.fineract/top/documents/clients/1/8q9sr/home/USER/public_html/top/tmp/client17.jpg (No such file or directory)",
"userMessageGlobalisationCode": "error.msg.document.save",
"parameterName": "id",
"value": null,
"args": [
{
"value": "/home/USER/public_html/top/tmp/client17.jpg"
},
{
"value": "/usr/share/tomcat7/.fineract/top/documents/clients/1/8q9sr/home/USER/public_html/top/tmp/client17.jpg (No such file or directory)"
}
]
}
]
Here the code that I am using:
// UPLOAD NEW FILES
if(ISSET($_FILES))
{
$uploads = array('guarantor_id_card', 'guarantor_payslip_1', 'guarantor_payslip_2', 'guarantor_payslip_3', 'guarantor_bank_1', 'guarantor_bank_2','guarantor_bank_3' );
$postFields = array();
// for creating documents
foreach($uploads as $k => $v)
{
// GET UPLOAD NAME FROM ARRAY
$upload_name = $v;
if(empty($_FILES[$upload_name]['error']))
{
$uploaddir = getcwd() . "/tmp/";
$uploadfile = $uploaddir . basename($_FILES[$upload_name]['name']);
if (move_uploaded_file($_FILES[$upload_name]['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Upload failed";
}
//files
$postFields['file'] = new CURLFile($uploadfile);
//metaData USING COUNTER AND UPLOAD NAME DYNAMIC
$postFields['fileName'] = $_FILES[$upload_name]['name'];
$postFields['type'] = $_FILES[$upload_name]['type'];
$postFields['name'] = 'Supporting Docs';
$postFields['description'] = $_FILES[$upload_name]['name'];
// initialise the curl request
$request = curl_init("https://APIURL_HERE");
// send a file
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_USERPWD, $user . ":" . $password);
curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
curl_setopt($request, CURLOPT_PORT, 8443);
curl_setopt($request, CURLOPT_SAFE_UPLOAD, TRUE);
curl_setopt($request, CURLOPT_POSTFIELDS, $postFields);
// output the response
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, 0);
$send_request = curl_exec($request);
// close the session
curl_close($request);
echo $send_request;
}
}
echo '<pre>';
echo 'Here is some more debugging info:';
print_r($_FILES);
print_r(getcwd());
echo '<br>';
print_r($uploadfile);
print "</pre>";
}
I'm out of ideas, if anyone has experience in this please do help!
Thanks.
So I've seen many examples of uploading an image via PHP using move_uploaded_file, but from the way that sounds, that would be a PHP script that resides on the server. In my case, I'm not trying to handle an uploaded file. I'm trying to submit a POST request and actually have the binary content of the file inserted with the HTTP POST request.
For example, my PHP script should be able to submit a form and include an image in its HTTP POST data, but I can't seem to figure this out or find valid examples specifically for doing this.
To further clarify, I am using CURL within PHP to submit this multipart/form-data.
Here's an example of what I have now:
function GetPostData($filename) {
if(!$filename) {
echo "The image doesn't exist ".$filename;
} else {
$data = [
'device_timestamp' => time(),
'photo' => '#'.$filename
];
return $data;
}
}
function SendRequest($url, $post, $data, $userAgent, $cookies) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://i.example.com/api/v1/'.$url);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_PROXY, 'http://192.168.1.21:8080');
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if($post) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
if($cookies) {
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
} else {
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
}
$response = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return [
'code' => $http,
'response' => $response,
];
}
.
$data = GetPostData($filename);
$post = SendRequest('media/upload/', true, $data, $agent, true);
But when I submit the image via the PHP script, this is what it looks like when I inspect the network traffic.
Content-Type: multipart/form-data; boundary=------------------------eee3f953c516cc55
Connection: close
--------------------------eee3f953c516cc55
Content-Disposition: form-data; name="device_timestamp"
1491023582
--------------------------eee3f953c516cc55
Content-Disposition: form-data; name="photo"
#/home/user/Desktop/square.jpeg
--------------------------eee3f953c516cc55--
Isn't the POST data supposed to contain the binary output of the image? How would the server save the image otherwise if just the path of the file is submitted in the form and not the actual image?
In other words, just like you would go to the terminal and type cat image.jpg, that's what I need PHP to submit in its form.
Solved my own problem by changing
function GetPostData($filename) {
if(!$filename) {
echo "The image doesn't exist ".$filename;
} else {
$data = [
'device_timestamp' => time(),
'photo' => '#'.$filename
];
return $data;
}
}
to this:
function GetPostData($filename) {
if(!$filename) {
echo "The image doesn't exist ".$filename;
} else {
$data = [
'device_timestamp' => time(),
'photo' => file_get_contents($filename)
];
return $data;
}
}
You have required to use in then you can easly uploded image
ex:-
<form action="" method="post" enctype="multipart/form-data">
</form>
PHP Code Required
<?php
if(isset($_POST['submit']))
{
$filename=$_FILES['Yourfilename']['name'];
$filetempname=$_FILES['Yourfilename']['tmp_name'];
$fname=md5($_SERVER['REMOTE_ADDR'].rand()).$filename;
$filepath1="uploads/folder name/".$fname;
move_uploaded_file($filetempname,$filepath1);
?>
I had a very simple PHP code to upload a file to a remote server; the way I was doing it (as has been suggested here in some other solutions) is to use cUrl to upload the file.
Here's my code:
$ch = curl_init("http://www.remotesite.com/upload.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('fileupload' => '#'.$_FILES['Filedata']['tmp_name']));
echo curl_exec($ch);
The server is running PHP 5.5.0 and it appears that #filename has been deprecated in PHP >= 5.5.0 as stated here under the CURLOPT_POSTFIELDS description, and therefore, I'm getting this error:
Deprecated: curl_setopt(): The usage of the #filename API for file uploading is deprecated. Please use the CURLFile class instead in ...
Interestingly, there is absolutely nothing about this Class on php.net aside from a basic class overview. No examples, no description of methods or properties. It's basically blank here. I understand that is a brand new class with little to no documentation and very little real-world use which is why practically nothing relevant is coming up in searches on Google or here on Stackoverflow on this class.
I'm wondering if there's anyone who has used this CURLFile class and can possibly help me or give me an example as to using it in place of #filename in my code.
Edit:
I wanted to add my "upload.php" code as well; this code would work with the traditional #filename method but is no longer working with the CURLFile class code:
$folder = "try/";
$path = $folder . basename( $_FILES['file']['tmp_name']);
if(move_uploaded_file($_FILES['file']['tmp_name'], $path)) {
echo "The file ". basename( $_FILES['file']['tmp_name']). " has been uploaded";
}
Final Edit:
Wanted to add Final / Working code for others looking for similar working example of the scarcely-documented CURLFile class ...
curl.php (local server)
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label> <input type="file" name="Filedata" id="Filedata" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if ($_POST['submit']) {
$uploadDir = "/uploads/";
$RealTitleID = $_FILES['Filedata']['name'];
$ch = curl_init("http://www.remotesite.com/upload.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$args['file'] = new CurlFile($_FILES['Filedata']['tmp_name'],'file/exgpd',$RealTitleID);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$result = curl_exec($ch);
}
?>
upload.php (remote server)
$folder = "try/";
$path = $folder . $_FILES['file']['name'];
if(move_uploaded_file($_FILES['file']['tmp_name'], $path)) {
echo "The file ". basename( $_FILES['file']['name']). " has been uploaded";
}
There is a snippet on the RFC for the code: https://wiki.php.net/rfc/curl-file-upload
curl_setopt($curl_handle, CURLOPT_POST, 1);
$args['file'] = new CurlFile('filename.png', 'image/png', 'filename.png');
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $args);
You can also use the seemingly pointless function curl_file_create( string $filename [, string $mimetype [, string $postname ]] ) if you have a phobia of creating objects.
curl_setopt($curl_handle, CURLOPT_POST, 1);
$args['file'] = curl_file_create('filename.png', 'image/png', 'filename.png');
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $args);
Thanks for your help, using your working code I was able to solve my problem with php 5.5 and Facebook SDK. I was getting this error from code in the sdk class.
I don't thinks this count as a response, but I'm sure there are people searching for this error like me related to facebook SDK and php 5.5
In case someone has the same problem, the solution for me was to change a little code from base_facebook.php to use the CurlFile Class instead of the #filename.
Since I'm calling the sdk from several places, I've just modified a few lines of the sdk:
In the method called "makeRequest" I made this change:
In this part of the code:
if ($this->getFileUploadSupport()){
$opts[CURLOPT_POSTFIELDS] = $params;
} else {
$opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
}
Change the first part (with file upload enabled) to:
if ($this->getFileUploadSupport()){
if(!empty($params['source'])){
$nameArr = explode('/', $params['source']);
$name = $nameArr[count($nameArr)-1];
$source = str_replace('#', '', $params['source']);
$size = getimagesize($source);
$mime = $size['mime'];
$params['source'] = new CurlFile($source,$mime,$name);
}
if(!empty($params['image'])){
$nameArr = explode('/', $params['image']);
$name = $nameArr[count($nameArr)-1];
$image = str_replace('#', '', $params['image']);
$size = getimagesize($image);
$mime = $size['mime'];
$params['image'] = new CurlFile($image,$mime,$name);
}
$opts[CURLOPT_POSTFIELDS] = $params;
} else {
$opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
}
Maybe this can be improved parsing every $param and looking for '#' in the value.. but I did it just for source and image because was what I needed.
FOR curl_setopt(): The usage of the #filename API for file uploading is deprecated. Please usethe CURLFile class instead
$img='image.jpg';
$data_array = array(
'board' => $board_id,
'note' => $note,
'image' => new CurlFile($img)
);
$curinit = curl_init($url);
curl_setopt($curinit, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curinit, CURLOPT_POST, true);
curl_setopt($curinit, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curinit, CURLOPT_POSTFIELDS, $data_array);
curl_setopt($curinit, CURLOPT_SAFE_UPLOAD, false);
$json = curl_exec($curinit);
$phpObj = json_decode($json, TRUE);
return $phpObj;
CURLFile has been explained well above, but for simple one file transfers where you don't want to send a multipart message (not needed for one file, and some APIs don't support multipart), then the following works.
$ch = curl_init('https://example.com');
$verbose = fopen('/tmp/curloutput.log', 'w+'); // Not for production, but useful for debugging curl issues.
$filetocurl = fopen(realpath($filename), 'r');
// Input the filetocurl via fopen, because CURLOPT_POSTFIELDS created multipart which some apis do not accept.
// Change the options as needed.
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => array(
'Content-type: application/whatever_you_need_here',
'Authorization: Basic ' . $username . ":" . $password) // Use this if you need password login
),
CURLOPT_NOPROGRESS => false,
CURLOPT_UPLOAD => 1,
CURLOPT_TIMEOUT => 3600,
CURLOPT_INFILE => $filetocurl,
CURLOPT_INFILESIZE => filesize($filename),
CURLOPT_VERBOSE => true,
CURLOPT_STDERR => $verbose // Remove this for production
);
if (curl_setopt_array($ch, $options) !== false) {
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
} else {
// A Curl option could not be set. Set exception here
}
Note the above code has some extra debug - remove them once it is working.
Php POST request send multiple files with curl function:
<?php
$file1 = realpath('ads/ads0.jpg');
$file2 = realpath('ads/ads1.jpg');
// Old method
// Single file
// $data = array('name' => 'Alexia', 'address' => 'Usa', 'age' => 21, 'file' => '#'.$file1);
// $data = array('name' => 'Alexia', 'address' => 'Usa', 'age' => 21, 'file[0]' => '#'.$file1, 'file[1]' => '#'.$file2);
// CurlFile method
$f1 = new CurlFile($file1, mime_content_type($file1), basename($file1));
$f2 = new CurlFile($file2, mime_content_type($file2), basename($file2));
$data = array('name' => 'Alexia', 'address' => 'Usa', 'age' => 21, 'file[1]' => $f1, 'file[2]' => $f2);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://url.x/upload.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); // !!!! required as of PHP 5.6.0 for files !!!
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // 1, 2
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$res2 = curl_exec($ch);
echo $res2;
?>
<?php
// upload.php
$json = json_decode(file_get_contents('php://input'), true);
if(!empty($json)){ print_r($json); }
if(!empty($_GET)){ print_r($_GET); }
if(!empty($_POST)){ print_r($_POST); }
if(!empty($_FILES)){ print_r($_FILES); }
?>