Reputation: 932
I'm developing a small proxy in PHP with cURL. It has to receive http requests from a client, make some statistics with this requests, foward the request to the web server and foward the responses to the client. Everything is working fine with GET requests and POST requests with text/html data.
I have problem to foward request with multipart/form-data data, in particular i have data both within the $_POST and $_FILES global variables.
How should I use these two variables to forward the request to the server?
Upvotes: 2
Views: 4977
Reputation: 7749
You will need to store the files in your server first, then use a code like this one :
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
"file_box"=>"@/path/to/myfile.jpg",
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
?>
Upvotes: 2