0

I have the issue that I can't seem to find out how to send large files via HTTP stream from a native PHP client to a CakePHP controller.

I thought about setting up an HTTP streaming plain PHP client, but this resulted only in 500 internal errors.

In this case, the controller I want to send the file to is called Users and the method (action) is called inbound_interface.

Here is my attempt:

$data = "";
for($i=0;$i<1000000000;$i++) $data .= "t";

$context_options = array (
        'http' => array (
            'method' => 'POST',
            'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
                . "Content-Length: " . strlen($data) . "\r\n"
                . "header: User-Agent:MyAgent/1.0\r\n",
            'content' => $data
            )
        );
        
$context = stream_context_create($context_options);

$fp = fopen('http://localhost/users/inbound_interface', 'r', false, $context);
Ahmad Adibzad
  • 501
  • 2
  • 6
  • 14
marius
  • 1,118
  • 1
  • 18
  • 38
  • i forgot to mention that the file is either xml or json – marius Apr 12 '17 at 09:52
  • 1
    That's kinda still the same question as **http://stackoverflow.com/questions/43346558/php-client-send-binary-data-to-cakephp**, isn't it? If you receive errors, check the logs and include the related information in your question (if it's an error on the CakePHP side be sure to include the stack trace additionally to the error message). That being said, start with using the proper content type, you surely don't want to send XML or JSON data as `application/x-www-form-urlencoded`, also don't use invalid dummy data, but proper XML or JSON. – ndm Apr 12 '17 at 14:25
  • Also depending on the actual size and how the data is being processed on the CakePHP side, you maybe better [**send the file as `multipart/form-data`**](http://stackoverflow.com/questions/4003989/upload-a-file-using-file-get-contents). – ndm Apr 12 '17 at 14:26

0 Answers0