. Rising Code Challenges Skip to main content

Posts

Showing posts from August, 2017

Send POST file using Curl in PHP

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. 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, CUR...