Curl is the most powerful Http Client. We can send any request using curl.
Today we will discuss about send a file with curl in PHP.
We will discuss to send file from our directory and also from a form.
On your curl url you can get all file in '$_FILES' .
All examples are have php >=5.5+
Today we will discuss about send a file with curl in PHP.
We will discuss to send file from our directory and also from a form.
File from directory
$this->fields = array(
"file" => curl_file_create('file/path/image.png', 'image/jpeg', 'file_name')
);
$http = curl_init();
curl_setopt($http, CURLOPT_URL, "example.com");
curl_setopt($http, CURLOPT_POST, true);
curl_setopt($http, CURLOPT_POSTFIELDS, $this->fields);
curl_setopt($http, CURLOPT_RETURNTRANSFER, true);
curl_exec($http);
File from Form
$this->fields = array(
"file" => curl_file_create($_FILES['file']['tmp_name'], $_FILES['file']['type'], $_FILES['file']['name'])
);
$http = curl_init();
curl_setopt($http, CURLOPT_URL, "example.com");
curl_setopt($http, CURLOPT_POST, true);
curl_setopt($http, CURLOPT_POSTFIELDS, $this->fields);
curl_setopt($http, CURLOPT_RETURNTRANSFER, true);
curl_exec($http);
On your curl url you can get all file in '$_FILES' .
All examples are have php >=5.5+
Comments
Post a Comment