php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #70794 Implement RFC 2231 for handling filenames in uploads
Submitted: 2015-10-26 15:20 UTC Modified: -
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: viskoo at gmail dot com Assigned:
Status: Open Package: HTTP related
PHP Version: 5.6.14 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: viskoo at gmail dot com
New email:
PHP Version: OS:

 

 [2015-10-26 15:20 UTC] viskoo at gmail dot com
Description:
------------
The aforementioned RFC deals with how to encode filenames when sending files as part of a POST request. If PHP receives a request from a client that implements this RFC, and the filename has special characters, the uploaded files will be lost ($_FILES will be empty), and a warning will be produced:

PHP Warning:  File Upload Mime headers garbled in Unknown on line 0

It doesn't matter if you put Apache, or nginx in front of PHP, or use the built in webserver.

http://tools.ietf.org/html/rfc2231

Test script:
---------------
Create an index.php file:

<?php

header('content-type', 'application/json');
echo json_encode($_FILES);

Launch the webserver with php -S localhost:9000.

Use this python script that uses the requests library to make an RFC 2231 compliant request:

import requests

filename = 'fårikål.txt'
destination = 'http://localhost:9000'
files = { filename: 'hello world' }

res = requests.post(destination, files=files)
print(res.status_code, res.text)

Expected result:
----------------
{
  "får": {
    "name": "får.txt",
    "type": "text/plain",
    "tmp_name": "/tmp/phpuXCXkF",
    "error": 0,
    "size": 12
  }
}

Actual result:
--------------
200 []

(empty result due to the warning, and status code 200)

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Dec 11 14:01:24 2019 UTC