From:             
Operating system: n/a
PHP version:      5.2.13
Package:          cURL related
Bug Type:         Feature/Change Request
Bug description:Setting filename for @... multipart uploads

Description:
------------
Using curl_setopt, you can make a multipart POST by passing an array of
parameters, and if preceded by an @, a file upload is created from the path
following the @.

  curl_setopt(CURLOPT_POSTFIELDS, array('myfile'=>"@{$pathname}"));

However, I haven't been able to find a way to set the filename part of the
multipart description, so that it generates e.g.

  Content-disposition: form-data; name="myfile";
filename="desiredfilename"

  Content-Type: text/plain

That is, there isn't a way to get "desiredfilename" in there. The only
option seems to be for the filename part appears to come from the name of
the file within the path. The cURL command line interface seems to support
explicitly setting the filename different from the name of the source file
with 

'-F "@path ; filename=whatever'

so presumably it is possible in the library, but not exposed through the
PHP binding.



In case it was merely passing on the string to the cURL library verbatim, I
tried:

 curl_setopt(CURLOPT_POSTFIELDS, array('myfile'=>"@{$pathname};
filename=\"desiredfilename\""));

but that gives an error.



The problem is that the files I have are stored with simple numeric names
and the file names which an external user would know them by are in the
database that indexes the disk files. I have a workround which is to make a
temporary hard link to the file by its user name and give that to cURL, but
I don't think I should really need to do that.

Test script:
---------------
    $now = time(); $tmpdirpath = "/tmp/enspub-{$now}-{$version->id}";

    mkdir($tmpdirpath);

    $tmpfilepath = "{$tmpdirpath}/" .
mb_ereg_replace('[/\\\\?%*:|"<>@~=+]', '_', $version->name); // replace
disallowed characters

    link($version->pathname(), $tmpfilepath);

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); /* tell me, not echo
*/

    curl_setopt($ch, CURLOPT_POST, TRUE);

    $post['file'] = "@{$tmpfilepath}"; 

    /* ... and other $post settings ... */

    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 

    $data = curl_exec($ch);

    /* ... error checking ... */

    curl_close($ch);

    @unlink($tmpfilepath);

    @rmdir($tmpdirpath);





Expected result:
----------------
It works, but I'd like to be able to set the filename explicitly without
copying the file.

Actual result:
--------------
n/a

-- 
Edit bug report at http://bugs.php.net/bug.php?id=51507&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=51507&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=51507&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=51507&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=51507&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=51507&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=51507&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=51507&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=51507&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=51507&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=51507&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=51507&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=51507&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=51507&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=51507&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=51507&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=51507&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=51507&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=51507&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=51507&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=51507&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=51507&r=mysqlcfg

Reply via email to