Bug #77617 [Asn->Fbk]: curl_setopt_array Triggers warning when used with CURLFile in CURLOPT_POSTFIELD

From: Date: Fri, 15 Feb 2019 21:20:00 +0000
Subject: Bug #77617 [Asn->Fbk]: curl_setopt_array Triggers warning when used with CURLFile in CURLOPT_POSTFIELD
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219599@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77617&edit=1 ID: 77617 Updated by: bishop@php.net Reported by: lawrence at dub3solutions dot com Summary: curl_setopt_array Triggers warning when used with CURLFile in CURLOPT_POSTFIELD -Status: Assigned +Status: Feedback Type: Bug Package: cURL related Operating System: CentOS 7 PHP Version: 7.2.15 Assigned To: bishop Block user comment: N Private report: N New Comment: This appears to depend very much on the exact file name path passed as the first argument to curl_file_create. Can you copy & paste an example of path raising this error, as well as provide information about what kind of filesystem this file resides? Additionally, can you try with this sample code: <?php error_reporting(-1); $file = tmpfile(); $path = stream_get_meta_data($file)['uri']; file_put_contents($path, md5(random_bytes(64))); $opts = [ CURLOPT_URL => 'https://postman-echo.com/post', CURLOPT_RETURNTRANSFER => 1, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => [ 'file' => curl_file_create($path), ], ]; $curl = curl_init(); $pass = curl_setopt_array($curl, $opts); Previous Comments: ------------------------------------------------------------------------ [2019-02-13 23:53:51] lawrence at dub3solutions dot com Description: ------------ When building an options array, setting one of the CURLOPT_POSTFIELDS key/values to a CURLFile object will result in the following PHP Warning: PHP Warning: curl_setopt_array(): Invalid filename for key variable_name When this warning is raised, curl_setopt_array returns true, and proceeds normally except it skips any files added. Not sure if this is the proper method, but I was asked to tag @bishop who was following my issue on stackoverflow. https://stackoverflow.com/questions/54680799/php-7-2-curlfile-gives-invalid-filename-warning Test script: --------------- $curl = curl_init(); $curlOpts = array( CURLOPT_POST => 1, CURLOPT_URL => $postUrl, CURLOPT_TIMEOUT => 20, CURLOPT_RETURNTRANSFER => 1, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => 'apikey' ); $postFields = array('var1' => 'value'); $postFields['variable_name'] = curl_file_create($filePath); $curlOpts[CURLOPT_POSTFIELDS] = $postFields; curl_setopt_array($curl, $curlOpts); $curl_response = curl_exec($curl); $info = curl_getinfo($curl); curl_close($curl); Expected result: ---------------- I would expect the file to get added to the curl options. Actual result: -------------- The file is ignored and a warning is added to the http logs PHP Warning: curl_setopt_array(): Invalid filename for key variable_name ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77617&edit=1

« previous php.bugs (#219599) next »