#48962 [NEW]: cURL does not upload files with specified filename
| From: | alexei dot svitkine at gmail dot com | Date: | Fri, 17 Jul 2009 16:14:20 +0000 |
| Subject: | #48962 [NEW]: cURL does not upload files with specified filename | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-139883@lists.php.net to get a copy of this message | ||
From: alexei dot svitkine at gmail dot com
Operating system: Linux
PHP version: 5.2.10
PHP Bug Type: cURL related
Bug description: cURL does not upload files with specified filename
Description:
------------
Currently, using cURL from PHP, it is not possible to specify a custom
filename on the file sent with the POST. PHP always tells cURL to send
the full path from the filesystem to the server.
However, it is possible to do this from the command-line using:
curl -F 'file=@/tmp/myfile;filename=foo.zip' http://example.com
This bug is similar to:
http://bugs.php.net/bug.php?id=46696
In that bug (which is now fixed), PHP ignored the 'type' parameter
which was passed in a similar way as 'filename' above, but was fixed
to detect it.
Reproduce code:
---------------
# File test1.php
$data = array('file' => '@/tmp/myfile;filename=foobar');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
echo curl_error($ch);
# File test2.php
$data = array('file' =>
'@/tmp/myfile;filename=foobar;type=application/zip');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
echo curl_error($ch);
# File upload.php
print_r($_FILES);
Expected result:
----------------
# Result of test1.php
Array
(
[item_file] => Array
(
[name] => foobar
[type] => application/octet-stream
[tmp_name] => /var/tmp/phpCEVFto
[error] => 0
[size] => 36257
)
)
# Result of test1.php
Array
(
[item_file] => Array
(
[name] => foobar
[type] => application/zip
[tmp_name] => /var/tmp/phpCEVFto
[error] => 0
[size] => 36257
)
)
Actual result:
--------------
The ";filename=foobar" part is either treated as part of the file path
(in test1.php), so the file is not found, and curl_exec() fails, or it
is treated as part of the 'type' (in test2.php), so incorrect
information is sent.
In either case, PHP currently does not look for the 'filename' parameter
as it does for the 'type' parameter, and handles it incorrectly. The fix
should be made to the "case CURLOPT_POSTFIELDS:" code in
ext/curl/interface.c, similar to how 'type' is already handled there.
This report applies to PHP 5.2.10 and PHP 5.3.0.
--
Edit bug report at http://bugs.php.net/?id=48962&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48962&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48962&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48962&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=48962&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48962&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=48962&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=48962&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=48962&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=48962&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=48962&r=support
Expected behavior: http://bugs.php.net/fix.php?id=48962&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=48962&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=48962&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=48962&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48962&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=48962&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=48962&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=48962&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=48962&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=48962&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=48962&r=mysqlcfg