-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* build: upgrade phpunit config * tweak: only close if already open * test: test coverage for curl class * test: test coverage for curlobjectlookup class * test: test coverage for curlobjectlookup class * test: test coverage for curlmulti class * test: test coverage for curlshare class * test: test coverage for curlmultiinfo class * docs: update examples * docs: update examples to use UploadFile * docs: update curl multi callback functions * tweak: phpmd
- Loading branch information
Showing
12 changed files
with
194 additions
and
16 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/* | ||
* This is the simplest example of how to perform an HTTP GET request using Curl | ||
*/ | ||
use Gt\Curl\Curl; | ||
|
||
require(__DIR__ . "/../vendor/autoload.php"); | ||
|
||
$curl = new Curl("https://ipapi.co/country_name"); | ||
$curl->exec(); | ||
echo "Your country is: "; | ||
echo $curl->output(), PHP_EOL; | ||
|
||
/* Example output: | ||
Your country is: United Kingdom | ||
*/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/* | ||
* This example downloads a picture of a cat, then uploads it to an example API | ||
* using an HTTP POST upload. | ||
*/ | ||
use Gt\Curl\Curl; | ||
use Gt\Curl\UploadFile; | ||
|
||
require(__DIR__ . "/../vendor/autoload.php"); | ||
|
||
$tmpFile = "/tmp/cat.jpg"; | ||
|
||
// Download a photo of a cat from cataas.com, save it to the $tmpFile | ||
$curl = new Curl("https://cataas.com/cat"); | ||
file_put_contents($tmpFile, $curl->output()); | ||
|
||
// Now POST a form containing the cat photo to the Postman echo test server | ||
$upload = new UploadFile($tmpFile); | ||
$curl = new Curl("https://postman-echo.com/post"); | ||
$curl->setOpt(CURLOPT_POSTFIELDS, [ | ||
"cat-photo" => $upload | ||
]); | ||
$curl->exec(); | ||
echo $curl->output(); | ||
|
||
// Remove the temporary file before finishing | ||
unlink($tmpFile); | ||
|
||
/* | ||
* Example output: | ||
* { | ||
* "args": {}, | ||
* "data": {}, | ||
* "files": { | ||
* "cat.jpg": "data:application/octet-stream;base64,/9j/4AAQSkZJRgABAQEIAAD" | ||
* }, | ||
* "form": {}, | ||
* "headers": { | ||
* "host": "postman-echo.com", | ||
* "content-length": "42285", | ||
* "accept": "*\/*", | ||
* "content-type": "multipart/form-data; boundary=--------------d7b86ee9056" | ||
* }, | ||
* "json": null, | ||
* "url": "https://postman-echo.com/post" | ||
* } | ||
*/ |
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
namespace Gt\Curl; | ||
|
||
use CURLFile; | ||
|
||
class UploadFile extends CURLFile {} |
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
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