Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: CURLStringFile::__construct - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: CURLStringFile::__construct

2025-06-02

CURLStringFile::__construct

(PHP 8 >= 8.1.0)

CURLStringFile::__construct创建 CURLStringFile 对象

说明

public CURLStringFile::__construct(string $data, string $postname, string $mime = "application/octet-stream")

创建 CURLStringFile 对象,使用 CURLOPT_POSTFIELDS 选项上传文件。

参数

data

待上传的内容。

postname

上传数据中的文件名称。

mime

文件的 MIME 类型(默认为 application/octet-stream)。

示例

示例 #1 CURLStringFile::__construct() 示例

<?php
/* http://example.com/upload.php:
<?php
var_dump($_FILES);
var_dump(file_get_contents($_FILES['test_string']['tmp_name']));
?>
*/

// 创建一个 cURL 句柄
$ch = curl_init('http://example.com/upload.php');

// 创建一个 CURLStringFile 对象
$cstringfile = new CURLStringFile('test upload contents','test.txt','text/plain');

// 指定 POST 内容
$data = array('test_string' => $cstringfile);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

// 执行句柄
curl_exec($ch);
?>

以上示例会输出:

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"

参见

添加备注

用户贡献的备注 1 note

up
0
inmarket
1 year ago
Note that the $postname and $mimetype parameters are in the reverse order to the CURLFile::__construct function.

官方地址:https://www.php.net/manual/en/curlstringfile.construct.php

冷却塔厂家 广告
中文GPT4.0无需注册 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3