array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'tr', ), 'this' => array ( 0 => 'curlstringfile.construct.php', 1 => 'CURLStringFile::__construct', ), 'up' => array ( 0 => 'class.curlstringfile.php', 1 => 'CURLStringFile', ), 'prev' => array ( 0 => 'class.curlstringfile.php', 1 => 'CURLStringFile', ), 'next' => array ( 0 => 'book.event.php', 1 => 'Event', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/curl/curlstringfile/construct.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 8 >= 8.1.0)
CURLStringFile::__construct — Create a CURLStringFile object
$data
, string $postname
, string $mime
= "application/octet-stream")
Creates a CURLStringFile object, used to upload a file with CURLOPT_POSTFIELDS
.
data
The contents to be uploaded.
postname
The name of the file to be used in the upload data.
mime
MIME type of the file (default is application/octet-stream
).
Örnek 1 CURLStringFile::__construct() example
<?php
/* http://example.com/upload.php:
<?php
var_dump($_FILES);
var_dump(file_get_contents($_FILES['test_string']['tmp_name']));
?>
*/
// Create a cURL handle
$ch = curl_init('http://example.com/upload.php');
// Create a CURLStringFile object
$cstringfile = new CURLStringFile('test upload contents','test.txt','text/plain');
// Assign POST data
$data = array('test_string' => $cstringfile);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// Execute the handle
curl_exec($ch);
?>
Yukarıdaki örneğin çıktısı:
array(1) { ["test_string"]=> array(5) { ["name"]=> string(8) "test.txt" ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) "/tmp/phpTtaoCz" ["error"]=> int(0) ["size"]=> int(20) } } string(20) "test upload contents"