在使用file_get_contents()函数期间收到错误消息,如何使用file_get_contents()函数上传文件?

时间:2018-07-14 09:20:02

标签: php mysql curl

我正在尝试将文件从一个域上传到使用了file_get_contents()函数的另一个域。

但是我不明白是什么问题?

这是我的代码:

Warning: file_get_contents(): failed to open stream: HTTP request failed! HTTP/1.1 406 Not Acceptable in 


 if(isset($fileupload))
 {
$postdata .= "--".MULTIPART_BOUNDARY."\r\n".
"Content-Disposition: form-data; name=\"s_id\"\r\n\r\n".
$_SESSION['s_id']."\r\n";
$postdata .= "--".MULTIPART_BOUNDARY."\r\n".
"Content-Disposition: form-data; name=\"s_deadline\"\r\n\r\n".
$_POST['deadline']."\r\n";
$postdata .= "--".MULTIPART_BOUNDARY."\r\n".
"Content-Disposition: form-data; name=\"s_wordcount\"\r\n\r\n".
$_POST['wordcount']."\r\n";
$postdata .= "--".MULTIPART_BOUNDARY."\r\n".
"Content-Disposition: form-data; name=\"s_subject\"\r\n\r\n".
$_POST['subject']."\r\n";
$postdata .= "--".MULTIPART_BOUNDARY."\r\n".
"Content-Disposition: form-data; name=\"s_university\"\r\n\r\n".
$_POST['university']."\r\n";
$postdata .= "--".MULTIPART_BOUNDARY."\r\n".
"Content-Disposition: form-data; name=\"s_notes\"\r\n\r\n".
$_POST['notes']."\r\n";
$postdata .= "--".MULTIPART_BOUNDARY."\r\n".
"Content-Disposition: form-data; name=\"s_submit\"\r\n\r\n".
"submit\r\n";
$postdata .= "--".MULTIPART_BOUNDARY."--\r\n";

$opts = array('http' =>
array(
'method'  => 'POST',
'header'  => 'Content-Type: multipart/form-data; 
 boundary='.MULTIPART_BOUNDARY,
'content' => $postdata
)
);
}
else{
    $postdata = http_build_query(
        array(
            's_id'          =>  $_SESSION['s_id'],
            's_deadline'    =>  $_POST['deadline'],
            's_wordcount'   =>  $_POST['wordcount'],
            's_subject'     =>  $_POST['subject'],
            's_university'  =>  $_POST['university'],
            's_notes'       =>  $_POST['notes'],
            's_submit'      =>  'submit'
        )
    );
    $opts = array('http' =>
                  array(
                      'method'  => 'POST',
                      'header'  => 'Content-type: 
                       application/x-www-form-urlencoded',
                      'content' => $postdata
 )
 );
}

$context  = stream_context_create($opts);
$file_data = file_get_contents($remote_site.'s/create_order_test.php', false, 
$context); 

0 个答案:

没有答案