PHP CURL: использование API @filename для загрузки файлов устарело

Я получил это сообщение:

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

Я знаю, что могу переписать свой код с CURLFile класса 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; } 

Я считаю, что это позволит вам использовать старый путь без предупреждения (если просто запретить использование @ не допустимо):

 curl_setopt($curl_handle, CURLOPT_SAFE_UPLOAD, false); 

См. Здесь