Skip to content

Instantly share code, notes, and snippets.

@Vijaysinh
Last active September 3, 2019 06:31
Show Gist options
  • Save Vijaysinh/bd6285ccf67c97f6363fcde194b24c4a to your computer and use it in GitHub Desktop.
Save Vijaysinh/bd6285ccf67c97f6363fcde194b24c4a to your computer and use it in GitHub Desktop.
File upload using CURL PHP
<!DOCTYPE html>
<html>
<head>
<title>Upload your files</title>
</head>
<body>
<form enctype="multipart/form-data" action="index.php" method="POST">
<p>Upload your file</p>
<input type="file" name="file"></input><br />
<input type="submit" value="Upload"></input>
</form>
</body>
</html>
<?PHP
if(!empty($_FILES['file']))
{
$path = "uploads/";
$path = $path . basename( $_FILES['file']['name']);
// if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) {
// echo "The file ". basename( $_FILES['uploaded_file']['name']).
// " has been uploaded";
// } else{
// echo "There was an error uploading the file, please try again!";
// }
make_Request();
}
function make_Request(){
$request = curl_init('https://xyz.com/url/function/attachment');
$filename = $_FILES['file']['name'];
$filedata = $_FILES['file']['tmp_name'];
$file = new CurlFile($filedata);
$file->setPostFilename($filename);
$postfields = array('file' => $file, "filename" => $filename,"conaxSupportId"=>1);
curl_setopt($request,CURLOPT_HTTPHEADER,array(
"User: trunk",
"Content-Type: multipart/form-data",
"RequestorUser: [email protected]",
));
curl_setopt($request,CURLOPT_POST,1);
curl_setopt($request, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($request, CURLOPT_POSTFIELDS,$postfields);
curl_setopt($request,CURLOPT_RETURNTRANSFER,true);
curl_setopt($request,CURLOPT_SSL_VERIFYPEER ,false);
var_dump(curl_exec($request));
curl_close($request);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment