PHP表單處理與檔案儲存

2021-07-31 20:38:16 字數 2417 閱讀 7981

_file 檔案上傳處理

move_uploaded_file 移動檔案

設定上傳檔案大小限制

php中,如果想要獲取通過get方法提交的資料,可以通過$_get物件來獲取

action="01.php"

method="get" >

for="">姓名:

type="text"

name= "username">

label>

type="text"

name= "useremail">

label>

type="submit"

name="">

form>

<?php

echo

""; echo

'username:'.$_get['username'];

echo'';

echo

'useremail:'.$_get['useremail'];

?>

php中,如果想要獲取通過post方法提交的資料,可以通過$_post物件來獲取

action="02.php"

method="post" >

for="">姓名:

type="text"

name= "username">

label>

type="text"

name= "useremail">

label>

type="submit"

name="">

form>

<?php

echo

""; echo

'username:'.$_post['username'];

echo'';

echo

'useremail:'.$_post['useremail'];

?>

當直接訪問post&get頁面時由於並沒有傳遞任何資料,會因為$_get$_post不存在對應的key而報錯.

if(array_key_exists('name', $_get))else
在php中 能夠通過$_file 獲取上傳的檔案

* 瀏覽器端部分**()

* 假定瀏覽器在form表單中如下標籤

*注1form提交資料需使用post提交

*注2form提交資料時,需在form表單中新增enctype=multipart/form-data屬性

action='xx.php'

method='post'

enctype='multipart/form-data'>

type='file'

name='icon'>

type='submit'>

form>

<?php

// 可以列印 $_files的所有資訊

print_r($_files);

?>

move_uploaded_file($_files['photo']['tmp_name'], './images/test.jpg');
修改php.ini

使用文字編輯工具的搜尋功能找到下列選項進行修改

* 設定檔案最大上傳限制(值的大小可以根據需求修改)

file_uploads = on            ; 是否允許上傳檔案 on/off 預設是on

upload_max_filesize = 32m ; 上傳檔案的最大限制

post_max_size = 32m ; 通過post提交的最多資料

max_execution_time = 30000      ; 指令碼最長的執行時間 單位為秒

max_input_time = 600 ; 接收提交的資料的時間限制 單位為秒

memory_limit = 1024m ; 最大的記憶體消耗

php提交表單處理,PHP表單處理

我們可以在php中建立和使用表單。要獲取表單資料,需要使用php超級元組 get和 post。表單請求可以是get或post。要從get請求中檢索資料,需要使用 get,而 post用於檢索post請求中的資料。php get表單 get請求是表單的預設請求。通過get請求傳遞的資料在url瀏覽器上...

PHP 表單處理

簡單html表單 welcome post 可以替換成 get your email address is get 是通過 url 引數傳遞到當前指令碼的變數陣列。get 可用於傳送非敏感的資料。注釋 絕不能使用 get 來傳送密碼或其他敏感資訊!post 是通過 http post 傳遞到當前指令...

php表單處理操作

最近在自學php,剛好學到了表單這一塊,就簡單說一下吧。首先,我這邊是用到了兩個軟體,乙個是phpstudy,另乙個是phpstorm。安裝也很簡單,我這裡就不多說了。步驟 1.開啟phpstudy 就是這樣 2.開啟編輯器,我的是用phpstorm,由於我的phpstudy是儲存在e盤下。所以我直...