Jonathan Costa
Jonathan Costa

Reputation: 29

How send and receive a file using curl using standard multi part form request?

Any way to do this? I search in all SOF threads and anyone answer is unutil, for no break rules of the community I can put my codes,

but sincerely, it's so easy.

If multipart-form-data is standard way to upload using post, why many peoples using /CurlFile, curl_file_create...

I search in Google using date tool (1 year last) and nothing.

Example:

 if (function_exists('curl_file_create')) { // php 5.5+
  $cFile = curl_file_create("unit.txt");
} else { // 
  $cFile = '@' . realpath($file_name_with_full_path);
}
$post = array('extra_info' => '123456','file_contents'=> $cFile);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://127.0.0.1/receive.php");
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
$result=curl_exec ($ch);

echo ">>>". $result;
curl_close ($ch);

I need know how to receive

Upvotes: 1

Views: 82

Answers (1)

How to send:

<?php

system('cmd /c & cd C:\xampp\apache\bin & httpd -k restart &curl --form "content=@C:\xampp\htdocs\THE_FILE.file" http://10.1.1.37/create.php');

?>

and how to receive:

<?php

move_uploaded_file($_FILES['content']['tmp_name'], "THE_FILE_2.file");

?>

Upvotes: 1

Related Questions