From:             
Operating system: All
PHP version:      5.4.0beta1
Package:          Streams related
Bug Type:         Feature/Change Request
Bug description:PUT request data should be parsed just like POST

Description:
------------
Data that is posted to PHP via the PUT method is not parsed at all and is
not 
available to PHP.
This is particularly problematic for data sent encoded as
'multipart/form-data'.

Basically, a request sent (with files and/or non-file data) via PUT should
be 
parsed using the same functions used for requests sent via 
POST.
Ideally, $_FILES and *either* $_POST or a new $_PUT superglobals should be

populated in PUT requests.


The answer is *not* to simply use parse_str() because that does not handle

multipart/form-data requests.

This is something that would help every RESTful interface that people are
trying 
to do with PHP.
There are many people who have these problems and have to implement
(usually 
incomplete and/or buggy) PHP solutions, 
eg: 
* Example of someone's wrong and incomplete solution: 
http://stackoverflow.com/questions/5483851/manually-parse-raw-
http-data-with-php
* Example of other people having problems: http://drupal.org/node/1270190


I ended up having to write half a page of code just to parse file and
normal 
data out of php://input stream which is not going to be as 
well tested or as stable as PHP's existing C code that parses the data when

using the POST method.


This could (possibly) be as simple as changing lines such as:
    `if(!strcmp(SG(request_info).request_method, "POST"))`
to
   `if(!strcmp(SG(request_info).request_method, "POST") || 
!strcmp(SG(request_info).request_method, "PUT"))`

or even adding a new superglobal called $_PUT (but still re-using
$_FILES).


Test script:
---------------
The request:

#!/bin/sh
curl "https://localhost/restful_server/"; -X PUT -F
"photo=@my_image.jpg;type=image/jpg" -F "foo=bar"

The php code:

<?php
echo "POST: \n"; var_dump($_POST);
echo "PUT: \n"; @var_dump($_PUT); // obviously this won't exist yet in php
5.4/5.3
echo "FILES: \n"; var_dump($_FILES);



Expected result:
----------------
POST: 
        array(0) {
}
PUT: 
        array(1) {
  ["foo"]=>
  string(3) "bar"
}
FILES: 
        array(1) {
  ["photo"]=>
  array(5) {
    ["name"]=>
    string(6) "my_image.jpg"
    ["type"]=>
    string(9) "image/jpg"
    ["tmp_name"]=>
    string(26) "/private/var/tmp/my_image.jpg"
    ["error"]=>
    int(0)
    ["size"]=>
    int(1)
  }
}

Actual result:
--------------
POST: 
        array(0) {
}
PUT: 
        NULL
FILES: 
        array(0) {
}

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

Reply via email to