PHP CURL: using @filename API to upload files is deprecated

I received this message:

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

I know that I can rewrite my code using the CURLFile class, but it is only available with 5.5.

My site should work on PHP 5.3, PHP 5.4 or PHP 5.5, so I can’t refuse compatibility between 5.3 and 5.4. Therefore, I can not use CURLFile.

How can I rewrite code so that it runs in any PHP without checking PHP versions?

+6
source share
2 answers

The best solution I found is /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; } 
+11
source

I believe that this will allow you to use the old method without warning (if simply prohibiting the use of @ not permissible):

 curl_setopt($curl_handle, CURLOPT_SAFE_UPLOAD, false); 

Look here

+5
source

All Articles