欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP響應(yīng)post請(qǐng)求上傳文件的方法

 更新時(shí)間:2015年12月17日 14:38:15   作者:龍魚鹿  
這篇文章主要介紹了PHP響應(yīng)post請(qǐng)求上傳文件的方法,涉及php針對(duì)post傳輸數(shù)據(jù)處理的相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了PHP響應(yīng)post請(qǐng)求上傳文件的方法。分享給大家供大家參考,具體如下:

function send_file($url, $post = '', $file = '') {
  $eol = "\r\n";
  $mime_boundary = md5 ( time () );
  $data = '';
  $confirmation = '';
  date_default_timezone_set ( "Asia/Shanghai" );
  $time = date ( "Y-m-d H:i:s " );
  $post ["filename"] = $file [filename];
  foreach ( $post as $key => $value ) {
    $data .= '--' . $mime_boundary . $eol;
    $data .= 'Content-Disposition: form-data; ';
    $data .= "name=" . $key . $eol . $eol;
    $data .= $value . $eol;
  }
  $data .= '--' . $mime_boundary . $eol;
  $data .= 'Content-Disposition: form-data; name=' . $file [name] . '; filename=' . $file [filename] . $eol;
  $data .= 'Content-Type: text/plain' . $eol;
  $data .= 'Content-Transfer-Encoding: binary' . $eol . $eol;
  $data .= $file [filedata] . $eol;
  $data .= "--" . $mime_boundary . "--" . $eol . $eol;
  $params = array ('http' => array ('method' => 'POST', 'header' => 'Content-Type: multipart/form-data;boundary=' . $mime_boundary . $eol, 'content' => $data ) );
  $ctx = stream_context_create ( $params );
  $response = file_get_contents ( $url, FILE_TEXT, $ctx );
  return $response;
}

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論