????/*
????*????@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函數做出測試。本人菜鳥一個。
2015-02-17
finfo得到文件類型的
^-^...
2015-02-19
謝謝老師,只是覺得每次遇到php需要擴展時,就覺得麻煩。動不動就缺什么驅動或擴展,想想也是本來就是開源的,看來需要將可能用到的擴展和驅動,整理歸列一下,以后在編譯安裝時一次搞定。避免這種情況。等有空了,我把驅動裝上。然后測試下finfo函數。