File tree Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ if ($ret) {
85
85
```
86
86
87
87
``` PHP
88
- //upload file
88
+ //Upload file
89
89
$postUrl = 'http://localhost/upload.php';//<?php var_dump($_FILES);
90
90
$c = new Curl();
91
91
$file1 = new \CURLFile('./olddriver.gif', 'image/gif', 'name1');
@@ -102,10 +102,30 @@ if ($ret) {
102
102
}
103
103
```
104
104
105
+ ``` PHP
106
+ //Download file
107
+ $fileUrl = 'http://localhost/test.gif';
108
+ $options = [//The custom the curl options
109
+ CURLOPT_TIMEOUT => 3600,//1 hour
110
+ CURLOPT_CONNECTTIMEOUT => 10,
111
+ ];
112
+ $c = new Curl($options);
113
+ $c->makeGet($fileUrl);
114
+ $ret = $c->exec();
115
+ var_dump($ret);
116
+ if ($ret) {
117
+ //Success
118
+ $targetFile = './a/b/c/test.gif';
119
+ var_dump($c->responseToFile($targetFile));
120
+ } else {
121
+ //Fail
122
+ var_dump($c->getError());
123
+ }
124
+ ```
125
+
105
126
## TODO
106
127
107
128
* HTTP PUT/DELETE
108
- * Download file
109
129
* Anything what you want
110
130
111
131
## License
Original file line number Diff line number Diff line change
1
+ <?php
2
+ require '../vendor/autoload.php ' ;
3
+
4
+ use Hhxsv5 \PhpMultiCurl \Curl ;
5
+
6
+ $ fileUrl = 'http://localhost/test.gif ' ;//<?php var_dump($_FILES);
7
+ $ options = [//The custom the curl options
8
+ CURLOPT_TIMEOUT => 3600 ,//1 hour
9
+ CURLOPT_CONNECTTIMEOUT => 10 ,
10
+ ];
11
+ $ c = new Curl ($ options );
12
+ $ c ->makeGet ($ fileUrl );
13
+ $ ret = $ c ->exec ();
14
+ var_dump ($ ret );
15
+ if ($ ret ) {
16
+ //Success
17
+ $ targetFile = './a/b/c/test.gif ' ;
18
+ var_dump ($ c ->responseToFile ($ targetFile ));
19
+ } else {
20
+ //Fail
21
+ var_dump ($ c ->getError ());
22
+ }
Original file line number Diff line number Diff line change @@ -118,6 +118,16 @@ protected function hasError()
118
118
return false ;
119
119
}
120
120
121
+ public function responseToFile ($ filename )
122
+ {
123
+ $ response = $ this ->getResponse ();
124
+ $ folder = dirname ($ filename );
125
+ if (!file_exists ($ folder )) {
126
+ mkdir ($ folder , 0777 , true );
127
+ }
128
+ return file_put_contents ($ filename , $ response );
129
+ }
130
+
121
131
public function getResponse ()
122
132
{
123
133
if ($ this ->response === null ) {
You can’t perform that action at this time.
0 commit comments