首页 > 代码库 > php中curl、fsockopen的应用

php中curl、fsockopen的应用

最近要用到通过post上传文件,网上盛传的有curl的post提交和fsockopen,其中curl最简单,于是从最简单的说起。这是简单的将一个变量post到另外一个页面$url = ‘‘;$data = http://www.mamicode.com/array(‘a‘=> ‘b‘);"--".$boundary."\r\n";                $out.="Content-Disposition: form-data; name=\"uploadFile\"; filename=\"".$file."\"\r\n";                $out.="Content-Type: image/jpg\r\n\r\n";                $out.=$content."\r\n";                $out.="--".$boundary."\r\n";                 fwrite($fp,"POST ".$uploadInfo[‘url‘]." HTTP/1.1\r\n");                fwrite($fp,"Host:".$uploadInfo[‘host‘]."\r\n");                fwrite($fp,"Content-Type: multipart/form-data; boundary=".$boundary."\r\n");                fwrite($fp,"Content-length:".strlen($out)."\r\n\r\n");                fwrite($fp,$out);                while (!feof($fp)){                        $ret .= fgets($fp, 1024);                }                fclose($fp);                $ret = trim(strstr($ret, "\r\n\r\n"));                preg_match(‘/http:.*/‘, $ret, $match);                return $match[0];

 

php中curl、fsockopen的应用