Files
php-curl-class/examples/upload_file.php
T
Zach Borboa acf8e9f6a0 Include curl error code constant in curl error message (Curl::curlErrorMessage)
Before:
    Timeout was reached: Operation timed out after 30001 milliseconds with 1453867 out of 3000000 bytes received

After:
    Timeout was reached (CURLE_OPERATION_TIMEOUTED): Operation timed out after 30001 milliseconds with 1453867 out of 3000000 bytes received
2022-09-30 07:52:27 -07:00

24 lines
651 B
PHP

<?php
require __DIR__ . '/../vendor/autoload.php';
use Curl\Curl;
$myfile = curl_file_create('cats.jpg', 'image/jpeg', 'test_name');
$curl = new Curl();
// HINT: If API documentation refers to using something like curl -F "myimage=image.png",
// curl --form "myimage=image.png", or the html form is similar to <form enctype="multipart/form-data" method="post">,
// then try uncommenting the following line:
// $curl->setHeader('Content-Type', 'multipart/form-data');
$curl->post('https://httpbin.org/post', [
'myfile' => $myfile,
]);
if ($curl->error) {
echo 'Error: ' . $curl->errorMessage . "\n";
} else {
echo 'Success' . "\n";
}