PHP響應post請求上傳文件的方法
更新時間:2015年12月17日 14:38:15 作者:龍魚鹿
這篇文章主要介紹了PHP響應post請求上傳文件的方法,涉及php針對post傳輸數(shù)據(jù)處理的相關技巧,需要的朋友可以參考下
本文實例講述了PHP響應post請求上傳文件的方法。分享給大家供大家參考,具體如下:
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;
}
希望本文所述對大家PHP程序設計有所幫助。
您可能感興趣的文章:
- php模擬post上傳圖片實現(xiàn)代碼
- PHP使用stream_context_create()模擬POST/GET請求的方法
- PHP使用curl模擬post上傳及接收文件的方法
- PHP模擬post提交數(shù)據(jù)方法匯總
- php提交post數(shù)組參數(shù)實例分析
- thinkPHP使用post方式查詢時分頁失效的解決方法
- php curl模擬post請求和提交多維數(shù)組的示例代碼
- PHP中Http協(xié)議post請求參數(shù)
- 利用PHP fsockopen 模擬POST/GET傳送數(shù)據(jù)的方法
- PHP 以POST方式提交XML、獲取XML,解析XML詳解及實例
相關文章
linux下的php-fpm參數(shù)配置介紹與參數(shù)優(yōu)化說明
本文主要講解了在linux下php-fpm一些重要參數(shù)的中文詳細說明,并詳細介紹了php-fpm關于性能方面的參數(shù)優(yōu)化介紹2017-12-12
CodeIgniter生成網(wǎng)站sitemap地圖的方法
用CodeIgniter只需要三步就可以生成網(wǎng)站sitemap地圖,方法很簡單,大家可以參考一下2013-11-11

