reference/curl/curlfile/construct.xml
5017547fee4dd0873d2ced02e2bb90b696f26a24
...
...
@@ -1,6 +1,5 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-

4
3
<refentry xml:id="curlfile.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
4
<refnamediv>
6
5
<refname>CURLFile::__construct</refname>
...
...
@@ -11,18 +10,18 @@
11
10
<refsect1 role="description">
12
11
&reftitle.description;
13
12
<para>&style.oop;</para>
14
-
<methodsynopsis>
13
+
<constructorsynopsis role="CURLFile">
15
14
<modifier>public</modifier> <methodname>CURLFile::__construct</methodname>
16
15
<methodparam><type>string</type><parameter>filename</parameter></methodparam>
17
-
<methodparam choice="opt"><type>string</type><parameter>mimetype</parameter></methodparam>
18
-
<methodparam choice="opt"><type>string</type><parameter>postname</parameter></methodparam>
19
-
</methodsynopsis>
16
+
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>mime_type</parameter><initializer>&null;</initializer></methodparam>
17
+
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>posted_filename</parameter><initializer>&null;</initializer></methodparam>
18
+
</constructorsynopsis>
20
19
<para>&style.procedural;</para>
21
20
<methodsynopsis>
22
21
<type>CURLFile</type><methodname>curl_file_create</methodname>
23
22
<methodparam><type>string</type><parameter>filename</parameter></methodparam>
24
-
<methodparam choice="opt"><type>string</type><parameter>mimetype</parameter></methodparam>
25
-
<methodparam choice="opt"><type>string</type><parameter>postname</parameter></methodparam>
23
+
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>mime_type</parameter><initializer>&null;</initializer></methodparam>
24
+
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>posted_filename</parameter><initializer>&null;</initializer></methodparam>
26
25
</methodsynopsis>
27
26
<para>
28
27
Creates a <classname>CURLFile</classname> object, used to upload a file with <constant>CURLOPT_POSTFIELDS</constant>.
...
...
@@ -41,7 +40,7 @@
41
40
</listitem>
42
41
</varlistentry>
43
42
<varlistentry>
44
-
<term><parameter>mimetype</parameter></term>
43
+
<term><parameter>mime_type</parameter></term>
45
44
<listitem>
46
45
<para>
47
46
Mimetype of the file.
...
...
@@ -49,7 +48,7 @@
49
48
</listitem>
50
49
</varlistentry>
51
50
<varlistentry>
52
-
<term><parameter>postname</parameter></term>
51
+
<term><parameter>posted_filename</parameter></term>
53
52
<listitem>
54
53
<para>
55
54
Name of the file to be used in the upload data.
...
...
@@ -66,6 +65,29 @@
66
65
</para>
67
66
</refsect1>
68
67

68
+
<refsect1 role="changelog">
69
+
&reftitle.changelog;
70
+
<informaltable>
71
+
<tgroup cols="2">
72
+
<thead>
73
+
<row>
74
+
<entry>&Version;</entry>
75
+
<entry>&Description;</entry>
76
+
</row>
77
+
</thead>
78
+
<tbody>
79
+
<row>
80
+
<entry>8.0.0</entry>
81
+
<entry>
82
+
<parameter>mime_type</parameter> and <parameter>posted_filename</parameter>
83
+
are nullable now; previously their default was <literal>0</literal>.
84
+
</entry>
85
+
</row>
86
+
</tbody>
87
+
</tgroup>
88
+
</informaltable>
89
+
</refsect1>
90
+

69
91
<refsect1 role="examples">
70
92
&reftitle.examples;
71
93
<example>
...
...
@@ -139,6 +161,112 @@ array(1) {
139
161
]]>
140
162
</screen>
141
163
</example>
164
+
<example>
165
+
<title><function>CURLFile::__construct</function> uploading multiple files example</title>
166
+
<para>&style.oop;</para>
167
+
<programlisting role="php">
168
+
<![CDATA[
169
+
<?php
170
+
$request = curl_init('http://www.example.com/upload.php');
171
+
curl_setopt($request, CURLOPT_POST, true);
172
+
curl_setopt($request, CURLOPT_SAFE_UPLOAD, true);
173
+
curl_setopt($request, CURLOPT_POSTFIELDS, [
174
+
'blob[0]' => new CURLFile(realpath('first-file.jpg'), 'image/jpeg'),
175
+
'blob[1]' => new CURLFile(realpath('second-file.txt'), 'text/plain'),
176
+
'blob[2]' => new CURLFile(realpath('third-file.exe'), 'application/octet-stream'),
177
+
]);
178
+
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
179
+

180
+
echo curl_exec($request);
181
+

182
+
var_dump(curl_getinfo($request));
183
+

184
+
curl_close($request);
185
+
]]>
186
+
</programlisting>
187
+
<para>&style.procedural;</para>
188
+
<programlisting role="php">
189
+
<![CDATA[
190
+
<?php
191
+
// procedural
192
+
$request = curl_init('http://www.example.com/upload.php');
193
+
curl_setopt($request, CURLOPT_POST, true);
194
+
curl_setopt($request, CURLOPT_SAFE_UPLOAD, true);
195
+
curl_setopt($request, CURLOPT_POSTFIELDS, [
196
+
'blob[0]' => curl_file_create(realpath('first-file.jpg'), 'image/jpeg'),
197
+
'blob[1]' => curl_file_create(realpath('second-file.txt'), 'text/plain'),
198
+
'blob[2]' => curl_file_create(realpath('third-file.exe'), 'application/octet-stream'),
199
+
]);
200
+
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
201
+

202
+
echo curl_exec($request);
203
+

204
+
var_dump(curl_getinfo($request));
205
+

206
+
curl_close($request);
207
+
]]>
208
+
</programlisting>
209
+
&example.outputs;
210
+
<screen>
211
+
<![CDATA[
212
+
array(26) {
213
+
["url"]=>
214
+
string(31) "http://www.example.com/upload.php"
215
+
["content_type"]=>
216
+
string(24) "text/html; charset=UTF-8"
217
+
["http_code"]=>
218
+
int(200)
219
+
["header_size"]=>
220
+
int(198)
221
+
["request_size"]=>
222
+
int(196)
223
+
["filetime"]=>
224
+
int(-1)
225
+
["ssl_verify_result"]=>
226
+
int(0)
227
+
["redirect_count"]=>
228
+
int(0)
229
+
["total_time"]=>
230
+
float(0.060062)
231
+
["namelookup_time"]=>
232
+
float(0.028575)
233
+
["connect_time"]=>
234
+
float(0.029011)
235
+
["pretransfer_time"]=>
236
+
float(0.029121)
237
+
["size_upload"]=>
238
+
float(3230730)
239
+
["size_download"]=>
240
+
float(811)
241
+
["speed_download"]=>
242
+
float(13516)
243
+
["speed_upload"]=>
244
+
float(53845500)
245
+
["download_content_length"]=>
246
+
float(811)
247
+
["upload_content_length"]=>
248
+
float(3230730)
249
+
["starttransfer_time"]=>
250
+
float(0.030355)
251
+
["redirect_time"]=>
252
+
float(0)
253
+
["redirect_url"]=>
254
+
string(0) ""
255
+
["primary_ip"]=>
256
+
string(13) "0.0.0.0"
257
+
["certinfo"]=>
258
+
array(0) {
259
+
}
260
+
["primary_port"]=>
261
+
int(80)
262
+
["local_ip"]=>
263
+
string(12) "0.0.0.0"
264
+
["local_port"]=>
265
+
int(34856)
266
+
}
267
+
]]>
268
+
</screen>
269
+
</example>
142
270
</refsect1>
143
271

144
272
<refsect1 role="seealso">
...
...
@@ -151,7 +279,6 @@ array(1) {
151
279
</refsect1>
152
280

153
281
</refentry>
154
-

155
282
<!-- Keep this comment at the end of the file
156
283
Local variables:
157
284
mode: sgml
158
285