Fowarding a multipart form data with php and cURL
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?
您需要先将文件存储在服务器中,然后使用如下代码:
<?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);
?>
链接地址: http://www.djcxy.com/p/48792.html
下一篇: 使用php和cURL支持多部分表单数据