php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49943 cURL does not upload files with specified filename
Submitted: 2009-10-21 12:56 UTC Modified: 2009-10-21 14:37 UTC
From: p dot watras at gmail dot com Assigned:
Status: Not a bug Package: cURL related
PHP Version: 5.2.11 OS: FreeBSD 7.1
Private report: No CVE-ID: None
 [2009-10-21 12:56 UTC] p dot watras at gmail dot com
Description:
------------
This bug is similar to http://bugs.php.net/bug.php?id=48962.
As alexei suggested you have to manually edit interface.c in line 1593:
and change it to:
CURLFORM_FILENAME, filename ? filename+sizeof(";filename=") - 1 : postval

Everything works fine after this update.



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:
--------------
Upload fails. No files are uploaded.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-21 13:35 UTC] jani@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

See bug #49921 and search before submit next time..
 [2009-10-21 14:37 UTC] p dot watras at gmail dot com
The problem was described in #48962 which is marked as CLOSED. On the other hand there already is a WORKING solution.

Anyway, I will search more thoroughly in future :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 02:01:28 2024 UTC