(PHP 5 >= 5.5.0, PHP 7)
CURLFile::__construct -- curl_file_create — Erstellt ein CURLFile Objekt
Objektorientierter Stil
$filename
[, string $mimetype
[, string $postname
]] )Prozeduraler Stil
Erstellt ein CURLFile, welches zum Upload einer Datei
via CURLOPT_POSTFIELDS verwendet wird.
filenamePfad zur Datei die hochgeladen wird.
mimetypeMimetyp der Datei.
postnameDer in den Upload-Daten zu verwendende Dateiname.
Gibt ein CURLFile-Objekt zurück.
Beispiel #1 CURLFile::__construct() Beispiel
Objektorientierter Stil
<?php
/* http://example.com/upload.php:
<?php var_dump($_FILES); ?>
*/
// Erstellt ein cURL handle
$ch = curl_init('http://example.com/upload.php');
// Erstellt ein CURLFile-Object
$cfile = new CURLFile('cats.jpg','image/jpeg','test_name');
// POST-Daten hinzufügen
$data = array('test_file' => $cfile);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// Das Handle ausführen
curl_exec($ch);
?>
Prozeduraler Stil
<?php
/* http://example.com/upload.php:
<?php var_dump($_FILES); ?>
*/
// Erstellt ein cURL-Handle
$ch = curl_init('http://example.com/upload.php');
// Erstellt ein CURLFile-Object
$cfile = curl_file_create('cats.jpg','image/jpeg','test_name');
// POST-Daten hinzufügen
$data = array('test_file' => $cfile);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// Handle ausführen
curl_exec($ch);
?>
Das oben gezeigte Beispiel erzeugt folgende Ausgabe:
array(1) {
["test_file"]=>
array(5) {
["name"]=>
string(9) "test_name"
["type"]=>
string(10) "image/jpeg"
["tmp_name"]=>
string(14) "/tmp/phpPC9Kbx"
["error"]=>
int(0)
["size"]=>
int(46334)
}
}