How to Send files via POST with cURL and PHP (Example)

Some web services ask to upload or Post some files on server. In this post we will explain you How to send files via Form Post. We are using cURl to send files on server.

cURL is very powerful library, you can Get or Post data using cURL method.

PHP cURL code to Send File

First create a simple HTML form to upload a file.

Make sure that form use ‘multipart/form-data‘ enctype value. This will post data in URL encrypted form.

Now create a receiver.php file to handle this form post request.

In this file cURL send file to any web server. Check it out below code:

If you found that file is imported as empty or any other issue, must upload the file in target path.

Than try to upload file again using html form. This will work without any issue.

Leave a Comment