1

我使用 jQuery File Upload 从客户端发布了一个文件a.php,但我需要将此信息转发到b.php(在不同的域上a.php)以进行进一步处理。如何使用 CURL 实现这一目标?谢谢!

4

2 回答 2

2

要转发$_FILES数据,您需要:

  1. 将文件保存在您的服务器上a.php
  2. 通过 POST 请求将该文件发送到b.php.

中的代码a.php可能如下所示:

$file_path = "full/path/to/upload/dir/" . basename($_FILES['my_file']['name']);
if(move_uploaded_file($_FILES['my_file']['tmp_name'], $file_path)) {
    $ch = curl_init('url/of/b.php'); 
    curl_setopt($ch, CURL_POST, TRUE);
    curl_setopt($ch, CURL_POSTFIELDS, array('my_file' => '@' . $file_path));
    $response = curl_exec($ch);
} else {
    echo "Can't save file";
}

b.php文件中将再次可用$_FILES['my_file']

于 2012-12-18T09:37:06.187 回答
0

像这样?

$filename = '/foo/bar';
$postargs = array(
  'foo' =>'bar', //normal postfield
  'fileentry' => '@'.$filename
);

$ch = curl_init(); 
curl_setopt($ch,CURL_POSTFIELDS, $postargs);//give as array for proper encoding.
curl_exec();
于 2012-12-18T08:10:03.770 回答