Last active
August 1, 2023 08:30
-
-
Save azhar25git/a6c807ff7a69681d425b38820dbd9d1a to your computer and use it in GitHub Desktop.
Send file with POST request via CURL PHP 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// You have to enable PHP CURL extension | |
//Initialise the cURL var | |
$ch = curl_init(); | |
// Path of the file | |
$file_uri = realpath('cat.zip'); | |
// Creates a CURLFile object, used to upload a file with CURLOPT_POSTFIELDS. | |
$file_to_send = curl_file_create($file_uri, '', ''); | |
// URL to send POST request | |
$url = "https://hooks.zapier.com/hooks/catch/4797032/788klv/"; | |
// Get the response from cURL | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
// Set the Url | |
curl_setopt($ch, CURLOPT_URL, $url); | |
// Create a POST array with the file in it | |
$postData = array( | |
'file' => $file_to_send, | |
// add any field and value to send | |
); | |
// Set POST fields | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); | |
// Receive server response ... | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
// Execute the request | |
$response = curl_exec($ch); | |
// Close connection | |
curl_close ($ch); | |
// Output server response | |
echo $server_output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment