yii使用bootstrap分页样式的实例
404
2024-01-17
php利用fsockopen GET/POST提交表单及上传文件,具体内容如下
1.GET
get.php
<?php $host = 'demo.fdipzone.com'; $port = 80; $errno = ''; $errstr = ''; $timeout = 30; $url = '/socket/getapi.php'; $param = array( 'name' => 'fdipzone', 'gender' => 'man' ); $url = $url.'?'.http_build_query($param); // create connect $fp = fsockopen($host, $port, $errno, $errstr, $timeout); if(!$fp){ return false; } // send request $out = "GET ${url} HTTP/1.1rn"; $out .= "Host: ${host}rn"; $out .= "Connection:closernrn"; fputs($fp, $out); // get response $response = ''; while($row=fread($fp, 4096)){ $response .= $row; } fclose($fp); $pos = strpos($response, "rnrn"); $response = substr($response, $pos+4); echo $response; ?>
getapi.php
<?php $name = $_GET['name']; $gender = $_GET['gender']; echo 'name='.$name.'<br>'; echo 'gender='.$gender; ?>
2.POST
post.php
<?php $host = 'demo.fdipzone.com'; $port = 80; $errno = ''; $errstr = ''; $timeout = 30; $url = '/socket/postapi.php'; $param = array( 'name' => 'fdipzone', 'gender' => 'man', 'photo' => file_get_contents('photo.jpg') ); $data = http_build_query($param); // create connect $fp = fsockopen($host, $port, $errno, $errstr, $timeout); if(!$fp){ return false; } // send request $out = "POST ${url} HTTP/1.1rn"; $out .= "Host:${host}rn"; $out .= "Content-type:application/x-www-form-urlencodedrn"; $out .= "Content-length:".strlen($data)."rn"; $out .= "Connection:closernrn"; $out .= "${data}"; fputs($fp, $out); // get response $response = ''; while($row=fread($fp, 4096)){ $response .= $row; } fclose($fp); $pos = strpos($response, "rnrn"); $response = substr($response, $pos+4); echo $response; ?>
postapi.php
<?php define('UPLOAD_PATH', dirname(__FILE__).'/upload'); $name = $_POST['name']; $gender = $_POST['gender']; $photo = $_POST['photo']; $filename = time().'.jpg'; file_put_contents(UPLOAD_PATH.'/'.$filename, $photo, true); echo 'name='.$name.'<br>'; echo 'gender='.$gender.'<br>'; echo '<img src="http://www.gimoo.net/t/1804/upload/'.$filename.'">'; ?>
3.上传文件
file.php
<?php $host = 'demo.fdipzone.com'; $port = 80; $errno = ''; $errstr = ''; $timeout = 30; $url = '/socket/fileapi.php'; $form_data = array( 'name' => 'fdipzone', 'gender' => 'man', ); $file_data = array( array( 'name' => 'photo', 'filename' => 'photo.jpg', 'path' =>'photo.jpg' ) ); // create connect $fp = fsockopen($host, $port, $errno, $errstr, $timeout); if(!$fp){ return false; } // send request srand((double)microtime()*1000000); $boundary = "---------------------------".substr(md5(rand(0,32000)),0,10); $data = "--$boundaryrn"; // form data foreach($form_data as $key=>$val){ $data .= "Content-Disposition: form-data; name="".$key.""rn"; $data .= "Content-type:text/plainrnrn"; $data .= rawurlencode($val)."rn"; $data .= "--$boundaryrn"; } // file data foreach($file_data as $file){ $data .= "Content-Disposition: form-data; name="".$file['name'].""; filename="".$file['filename'].""rn"; $data .= "Content-Type: ".mime_content_type($file['path'])."rnrn"; $data .= implode("",file($file['path']))."rn"; $data .= "--$boundaryrn"; } $data .="--rnrn"; $out = "POST ${url} HTTP/1.1rn"; $out .= "Host:${host}rn"; $out .= "Content-type:multipart/form-data; boundary=$boundaryrn"; // multipart/form-data $out .= "Content-length:".strlen($data)."rn"; $out .= "Connection:closernrn"; $out .= "${data}"; fputs($fp, $out); // get response $response = ''; while($row=fread($fp, 4096)){ $response .= $row; } fclose($fp); $pos = strpos($response, "rnrn"); $response = substr($response, $pos+4); echo $response; ?>
fileapi.php
<?php define('UPLOAD_PATH', dirname(__FILE__).'/upload'); $name = $_POST['name']; $gender = $_POST['gender']; $filename = time().'.jpg'; echo 'name='.$name.'<br>'; echo 'gender='.$gender.'<br>'; if(move_uploaded_file($_FILES['photo']['tmp_name'], UPLOAD_PATH.'/'.$filename)){ echo '<img src="http://www.gimoo.net/t/1804/upload/'.$filename.'">'; } ?>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持绿夏网。
#免责声明#
本站[绿夏技术导航]提供的一切软件、教程和内容信息仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络收集整理,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑或手机中彻底删除上述内容。如果您喜欢该程序或内容,请支持正版,购买注册,得到更好的正版服务。我们非常重视版权问题,如有侵权请邮件[admin@lxwl520.com]与我们联系进行删除处理。敬请谅解!