亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

單文件上傳(未精簡三)

????/*
????*????@function?移動文件參數初始化
????*????@notice?初始化新文件名,新文件路徑,檢測與創建文件路徑,構成最終全路徑
????*/
????public?function?move_params_init(){
????????$newFileName=$this->createNewFileName();
????????$newFilePath=$this->getSequencePath($newFileName);
????????$this->createFileDir($newFilePath);
????????$this->destination=$newFilePath.$newFileName;
????}

????/*
????*????@function?創建新文件名
????*????@return?string?新文件名
????*????@notice?文件名由?當前時間_隨機數_毫秒數_文件類型.后綴名
????*/
????public?function?createNewFileName(){
????????list($usec,$sec)=explode("?",microtime());
????????$new_file_name=date("YmdHis")."_".mt_rand(1000,9999)."_".substr($sec,2,5)."_".$this->file_category.".".$this->temp_fileExt;
????????return?$new_file_name;
????}
????
????/*
????*????@function?獲取序列化的文件路徑
????*????@param?$newFileName?新文件名
????*????@return?string
????*/
????public?function?getSequencePath($newFileName){
????????$extension_dir=substr(md5($newFileName),0,1)."/".substr(md5($newFileName),1,1);//擴展目錄
????????$path=$this->rootPath.$this->file_category;//固定目錄
????????$sequence_path=$path."/".$extension_dir."/";
????????return?$sequence_path;
????}
????
????/*
????*????@function?檢測目錄是否存在,不存在就創建
????*????@param?$path目錄
????*/
????public?function?createFileDir($path){
????????if(!is_dir($path)){
????????????$tmp_path=dirname($path);
????????????$this->createFileDir($tmp_path);
????????????@mkdir($path,0777,true);
????????????chmod($path,0777);
????????}
????????else{
????????????return;
????????}
????}
}
/*
$allow_type=array(
????????"image"=>array(
????????????"png","jpeg","jpg","gif",
????????),
????????"file"=>array(
????????????"rar","zip",
????????),
????????"video"=>array(
????????????"avi","flv","wmv","mp4","vob","rmvb",
????????),
);

$allow_size=102400;
$rootPath="./upload/";
$fileUpload=new?FileUpload($name,$allow_size,$allow_type,$rootPath);
$fileUpload->move_file();
*/
?>
各位大大們,幫忙看下,特別指出下有誰試過finfo_open這個函數沒,因為PHP版本沒有到5.3以上,所以無法對finfo_open函數做出測試。本人菜鳥一個。


正在回答

2 回答

finfo得到文件類型的

^-^...

0 回復 有任何疑惑可以回復我~

謝謝老師,只是覺得每次遇到php需要擴展時,就覺得麻煩。動不動就缺什么驅動或擴展,想想也是本來就是開源的,看來需要將可能用到的擴展和驅動,整理歸列一下,以后在編譯安裝時一次搞定。避免這種情況。等有空了,我把驅動裝上。然后測試下finfo函數。

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
PHP實現文件上傳與下載
  • 參與學習       43750    人
  • 解答問題       338    個

本課程講解了文件上傳的原理和配置,學會兩種方式實現文件上傳與下載

進入課程

單文件上傳(未精簡三)

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號