imnotjames / curlfile-compat
Compatibility library with CURLFile from PHP 5.5
Installs: 3 889
Dependents: 2
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 0
Requires (Dev)
- phpunit/phpunit: 4.*
- satooshi/php-coveralls: dev-master
This package is not auto-updated.
Last update: 2022-08-06 04:53:51 UTC
README
Compatibility library to add a CURLFile class to older versions of PHP. The RFC has some more information on it as well.
This class abuses the fact that the PHP CURLOPT_POSTFIELDS
option will coerce classes to strings when
sending it as data, and outputs the older style of including files in the post data.
Installation
New school or old school, your choice.
For a new school installation with Composer simply add it to your list of dependencies.
If you're kicking it old school you've got to require
src/CURLFile.php
and src/imnotjames/CURLFILE.php
.
Either way, the non-namespaced CURLFile will only be created if the class doesn't already exist. Same goes for the create_curl_file
function.
Usage
Exactly the same as PHP's CURLFile'
$handle = curl_init('http://example.com'); $cfile = new CURLFile('puppy.jpg','image/jpeg','puppy_boquet'); // Assign POST data $data = array('test_file' => $cfile); curl_setopt($handle, CURLOPT_POST, true); curl_setopt($handle, CURLOPT_POSTFIELDS, $data); curl_exec($handle);