PHP商城筆記 檔案上傳6 檔案上傳類

2021-08-21 14:16:48 字數 1601 閱讀 1090

uptool.class.php

/*

單檔案上傳類

多檔案上傳由同學們自己擴充套件

*/defined('acc')||exit('acc denied');

/*上傳檔案

配置允許的字尾

配置允許的大小

隨機生成目錄

隨機生成檔名

獲取檔案字尾

判斷檔案的字尾.

良好的報錯的支援

*/class

uptool

$f = $_files[$key];

// 檢驗上傳有沒有成功

if($f['error'])

// 獲取字尾

$ext = $this->getext($f['name']);

// 檢查字尾

if(!$this->isallowext($ext))

// 檢查大小

if(!$this->isallowsize($f['size']))

// 通過,就該上傳了,但首先得建立目錄

//建立目錄

$dir = $this->mk_dir();

if($dir == false)

// 生成隨機檔名

$newname = $this->randname() . '.' . $ext;

$dir = $dir . '/' . $newname;

// 移動

if(!move_uploaded_file($f['tmp_name'],$dir))

return str_replace(root,'',$dir);

}public

function

geterr

() /*

parm string $exts 允許的字尾

*/public

function

setext

($exts)

public

function

setsize

($num)

/*parm string $file

return string $ext 字尾

*/protected

function

getext

($file)

/*parm string $ext 判斷檔案字尾

return bool

防止大小寫的問題 jpg

*/protected

function

isallowext

($ext)

// 檢查檔案的大小

protected

function

isallowsize

($size)

/*按日期建立目錄的方法

*/protected

function

mk_dir

() else }/*

生成隨機檔名

*/protected

function

randname

($length = 6)

}

php筆記3 檔案上傳

目錄 上傳頭像 php呼叫js 垂直對齊方式 mkdir 效果 時間戳 unix 時間戳 date 時區prc 檔案上傳 前端使用 input type file method 使用post enctype 加上上傳路徑 files 接收name 屬性的引數,校驗上傳檔案型別 為每個使用者建立唯一資...

php基礎四 檔案上傳

檔案上傳之需要注意php.ini檔案 php.ini檔案中的配置 file uploads post max size upload max filesize memory limit print r files upfile if is uploaded file files upfile tmp...

Php學習《四》 檔案上傳

b 通過 php,可以把檔案上傳到伺服器。b b 建立乙個檔案上傳表單 b 允許使用者從表單上傳檔案是非常有用的。請看下面這個供上傳檔案的 html 表單 請留意如下有關此表單的資訊 標籤的 enctype 屬性規定了在提交表單時要使用哪種內容型別。在表單需要二進位制資料時,比如檔案內容,請使用 m...