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.

Recommended Posts For You

About Harish

I am professional web developer and blogger. Use this blog to share own api and other web development experience with you. I do accept paid work. Write to me at - [email protected]

View all posts by Harish

Leave a Comment

Your email address will not be published. Required fields are marked *