Skip to content

Instantly share code, notes, and snippets.

@Daniyal-Javani
Last active March 16, 2018 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daniyal-Javani/58844db7ef1a89e6de5888958c19a042 to your computer and use it in GitHub Desktop.
Save Daniyal-Javani/58844db7ef1a89e6de5888958c19a042 to your computer and use it in GitHub Desktop.
Upload using curl and receive it locally in php
<?php
echo "<pre>";
echo 'in upload.php<br/>';
print_r($_FILES);
print_r($_REQUEST);
move_uploaded_file($_FILES["file_contents"]["tmp_name"], "upload/".$_FILES["file_contents"]["name"]);
<?php
$file_name_with_full_path = 'tables';
$target_url = 'http://localhost/upload.php';
if (function_exists('curl_file_create')) { // php 5.5+
$cFile = curl_file_create($file_name_with_full_path);
} else { //
$cFile = '@' . realpath($file_name_with_full_path);
}
$post = array('extra_info' => '123456','file_contents'=> $cFile);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment