gpt4 book ai didi

PHP curl : The usage of the @filename API for file uploading is deprecated

转载 作者:可可西里 更新时间:2023-11-01 13:08:38 25 4
gpt4 key购买 nike

我收到这条消息:

Deprecated: curl_setopt_array(): The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead

我知道我可以使用 CURLFile 类重写我的代码,但它只能从 5.5 开始使用。

我的网站必须在 PHP 5.3、PHP 5.4 或 PHP 5.5 上运行,所以我不能放弃 5.3 和 5.4 的兼容性。所以我不能使用 CURLFile。

如何重写代码以使其在没有任何 PHP 版本检查的情况下在任何 PHP 上运行?

最佳答案

我找到的最佳解决方案是 /src/Guzzle/Http/Message/PostFile.php :

public function getCurlValue()
{
// PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax
// See: https://wiki.php.net/rfc/curl-file-upload
if (function_exists('curl_file_create')) {
return curl_file_create($this->filename, $this->contentType, $this->postname);
}

// Use the old style if using an older version of PHP
$value = "@{$this->filename};filename=" . $this->postname;
if ($this->contentType) {
$value .= ';type=' . $this->contentType;
}

return $value;
}

关于PHP curl : The usage of the @filename API for file uploading is deprecated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20972513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com