(PHP 5 >= 5.5.0, PHP 7)
CURLFile::__construct -- curl_file_create — Criar um objeto CURLFile
Estilo orientado à objeto
$filename
[, string $mimetype
[, string $postname
]] )Estilo procedural
Cria um objeto CURLFile, usado para o upload de um arquivo CURLOPT_POSTFIELDS
.
filename
Caminho para onde arquivo que será enviado.
mimetype
O mimetype do arquivo.
postname
Nome do arquivo a ser usado nos dados de upload.
Retorna um objeto CURLFile.
Exemplo #1 CURLFile::__construct() example
Estilo orientado à objeto
<?php
/* http://example.com/upload.php:
<?php var_dump($_FILES); ?>
*/
// Cria um manipulador cURL
$ch = curl_init('http://example.com/upload.php');
// Cria um objeto CURLFile
$cfile = new CURLFile('cats.jpg','image/jpeg','test_name');
// Atribui dados ao POST
$data = array('test_file' => $cfile);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// Executa o manipulador
curl_exec($ch);
?>
Estilo procedural
<?php
/* http://example.com/upload.php:
<?php var_dump($_FILES); ?>
*/
// Cria um manipulador cURL
$ch = curl_init('http://example.com/upload.php');
// Cria um objeto CURLFile
$cfile = curl_file_create('cats.jpg','image/jpeg','test_name');
// Atribui dados ao POST
$data = array('test_file' => $cfile);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// Executa o manipulador
curl_exec($ch);
?>
O exemplo acima irá imprimir:
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) } }