php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #27023 CURL: CURLOPT_POSTFIELDS does not parse content types for files
Submitted: 2004-01-23 13:26 UTC Modified: 2011-12-07 16:36 UTC
Votes:5
Avg. Score:4.6 ± 0.5
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:4 (100.0%)
From: brianl at stcu dot org Assigned: pierrick (profile)
Status: Closed Package: cURL related
PHP Version: * OS: *
Private report: No CVE-ID: None
 [2004-01-23 13:26 UTC] brianl at stcu dot org
Description:
------------
From the cURL manual:

If you want the contents to be read from a file, use <@filename> as contents. When specifying a file, you can also specify the file content type by appending ';type=<mime type>' to the file name.

However, specifing MIME types is not currently supported within PHP.

Reproduce code:
---------------
$ch= curl_init('http://www.example.com/fupl.php');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,
  array('field1'=>'1','field2'=>'2','file'=>'@filepath.ext;type=application/xml'));
$result= curl_exec($ch);
curl_close($ch);

Expected result:
----------------
The file should be uploaded with a Content-Type: application/xml header.

Actual result:
--------------
The entire call fails.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-25 19:02 UTC] sniper@php.net
This is not bug but feature request.
Passing just "@/path/to/file.ext" works fine.
The content-type is detected by curl (if it can).

Reclassified.

 [2004-03-07 11:54 UTC] brianl at stcu dot org
Since curl's ability to guess the MIME type of a file by extension is extremely limited, this represents a very important enhancement for any upload where the MIME type is used.
 [2005-02-24 03:28 UTC] jplock at yahoo dot com
I would very much like this functionality to be implemented in PHP5 as I need it for a project I am currently developing. Thanks.
 [2010-11-19 01:15 UTC] jani@php.net
-Package: Feature/Change Request +Package: cURL related -PHP Version: 4CVS, 5CVS +PHP Version: *
 [2011-12-07 16:36 UTC] pierrick@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: pierrick
 [2011-12-07 16:36 UTC] pierrick@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

Feature implemented since the bug report.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 23:01:29 2024 UTC