How to send files using cURL and PHP

6 minutes read

How to upload a file from one server to another server using PHP cURL POST method.

How to send files using PHP and cURL

How to send files using PHP and cURL

The cURL functions in PHP can be used to make HTTP requests to remote servers.
The curl_setopt  method allows us a wide range of options to be set, but no one of them directly related to send files.
But we can send files using cURL with special format for POST parameter values.
Following script is usefull in sending a binary file via cURL.

This code will make a request to http://demo.phpmysqlquery.com/, uploads the file demo.txt, and return the output as response.

 

 

And now here is the corresponding script on destination server to accept the file.

 

Note :We can transfer any type of files like photo(.png,.jpg), .xls and .csv files from one server to another server using this script.

Facebook Twitter LinkedIn Telegram Whatsapp

Related Posts:

cURL is a best library for file transfer via different types of protocols. cURL supports the transport via POST, GET, FTP upload and much more. cURL is also able to authenticate on the destination server or website. How to send files using PHP and cURL In this...
What is PHP ? PHP stands for Hypertext Preprocessor and is a server-side language. PHP allows web developers to create dynamic content that interacts with databases. PHP is relatively new (compared to languages such as Perl (CGI) and Java) but is quickly becom...
Some times we need the visitor’s IP address for validation, security, spam prevention etc. Getting the Visitor’s IP address is very easy in PHP. We can get the Internet Protocol (IP) address of any visitor by using PHP. Get Clients IP address using PHP script ...