一、用file_get_contents以get方式獲取內(nèi)容,需要輸入內(nèi)容為:
創(chuàng)新互聯(lián)主營阿榮網(wǎng)站建設的網(wǎng)絡公司,主營網(wǎng)站建設方案,重慶APP開發(fā)公司,阿榮h5小程序制作搭建,阿榮網(wǎng)站營銷推廣歡迎阿榮等地區(qū)企業(yè)咨詢
1、?php
2、$url='';
3、$html=file_get_contents($url);
4、echo$html;
5、?
二、用file_get_contents函數(shù),以post方式獲取url,需要輸入內(nèi)容為
1、?php
2、$url='';
3、$data=array('foo'='bar');
4、$data=http_build_query($data);
5、$opts=array(
6、'http'=array(
7、?'method'='POST',
8、?'header'="Content-type:application/x-www-form-urlencoded\r\n".
9、??????????"Content-Length:".strlen($data)."\r\n",
10、?'content'=$data
11、)
12、);
13、$ctx=stream_context_create($opts);
14、$html=@file_get_contents($url,'',$ctx);
15、?
三、用fopen打開url,以get方式獲取內(nèi)容,需要輸入內(nèi)容為
1、?php
2、$fp=fopen($url,'r');
3、$header=stream_get_meta_data($fp);//獲取信息
4、while(!feof($fp)){
5、$result.=fgets($fp,1024);
6、}
7、echo"urlheader:{$header}br":
8、echo"urlbody:$result";
9、fclose($fp);
10、?
四、用fopen打開url,以post方式獲取內(nèi)容,需要輸入內(nèi)容為
1、?php
2、$data=array('foo2'='bar2','foo3'='bar3');
3、$data=http_build_query($data);
4、$opts=array(
5、'http'=array(
6、'method'='POST',
7、'header'="Content-type:application/x-www-form-urlencoded\r\nCookie:cook1=c3;cook2=c4\r\n".
8、"Content-Length:".strlen($data)."\r\n",
9、'content'=$data
10、)
11、);
12、$context=stream_context_create($opts);
13、$html=fopen(';id2=i4','rb',false,$context);
14、$w=fread($html,1024);
15、echo$w;
16、?
五、用fsockopen函數(shù)打開url,以get方式獲取完整的數(shù)據(jù),包括header和body,需要輸入內(nèi)容為
1、?php
2、functionget_url($url,$cookie=false)
3、{
4、$url=parse_url($url);
5、$query=$url[path]."?".$url[query];
6、echo"Query:".$query;
7、$fp=fsockopen($url[host],$url[port]?$url[port]:80,$errno,$errstr,30);
8、if(!$fp){
9、returnfalse;
10、}else{
11、$request="GET$queryHTTP/1.1\r\n";
12、$request.="Host:$url[host]\r\n";
13、$request.="Connection:Close\r\n";
14、if($cookie)$request.="Cookie:??$cookie\n";
15、$request.="\r\n";
16、fwrite($fp,$request);
17、while(!@feof($fp)){
18、$result.=@fgets($fp,1024);
19、}
20、fclose($fp);
21、return$result;
22、}
23、}
24、//獲取url的html部分,去掉header
25、functionGetUrlHTML($url,$cookie=false)
26、{
27、$rowdata=get_url($url,$cookie);
28、if($rowdata)
29、{
30、$body=stristr($rowdata,"\r\n\r\n");
31、$body=substr($body,4,strlen($body));
32、return$body;
33、}
34、?returnfalse;
35、}
36、?
參考資料:
php-file_get_contents
把按鈕的屬性type 寫為submit或者button,例如input type='submit' class="pic" /在pic類中添加一個圖片就行了,至于寫進數(shù)據(jù)庫這步,可以在表單form標簽加上一個action屬性,在另一個頁面或者是本頁面用$_session[],接收表單的值就行了,再用insert 插入就行了
php接收表單數(shù)據(jù)的話是可以接收上傳圖片和文字表單信息的,在表單中有文件上傳的時候記得表單的form屬性的method要是post,并且在添加一個屬性enctype="multipart/form-data"。這樣就可以達到圖片和文字一起傳遞了,事例代碼如下:
form?action="xxx.php"?method="post"?enctype="multipart/form-data"
input?type="text"?name="username"?/
input?type="file"?name="file"?/
input?type="submit"?value="Submit"?/
/form
在處理這樣的php文件中直接打印$_POST和$_FILES這兩個超全局數(shù)組就可以看到提交的數(shù)據(jù)內(nèi)容了。
。。。。
插入圖片file控件實現(xiàn)的,上傳實際上是將圖片上傳到了服務器上面,然后獲得圖片存儲的路徑。數(shù)據(jù)庫存儲的不是圖片,而是這里的路徑。
代碼如下:
html:
form action="你的路徑" enctype="multipart/form-data" method=“post”
input type="file" value="上傳圖片" name="pic"
textarea name="content"/textarea
/from
這里提交到php頁面,也就是你路徑指向的位置:
php:
$file = $_FILES["pic"]["name"]; //提取文件域內(nèi)容名稱,并判斷
$path=”aaa/”; //上傳路徑 .這個路徑必須真實存在,否則會出錯,或者你判定下這個路徑是否存在,如果不存在則生成文件,這里我就不寫了。判定圖片格式我也沒有寫,如果你想要,從網(wǎng)上下載很多上傳圖片的類庫,簡單方便.
$file2 = $path.$file;//文件將要放到的位置
$result=move_uploaded_file($_FILES["img"]["tmp_name"],$file2); //將臨時文件移動到指定目錄下
$content = $_POST['content'];
然后插入到數(shù)據(jù)庫中:
insert into 表 (‘pic’,'content') values ('".$file2."','".$content."');
本文標題:php表單提交圖片數(shù)據(jù) php form表單提交圖片
文章出自:http://muchs.cn/article4/dohopoe.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護、移動網(wǎng)站建設、網(wǎng)站設計、虛擬主機、外貿(mào)網(wǎng)站建設、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)