封裝的上傳類
<?php
header('connect-type:text/html;charset=utf-8');
/*檔案上傳類*/
class upload
/*判斷檔案型別*/
/*判斷檔案錯誤** */
switch ($fileerror)
/*判斷檔案目錄
param string $path 檔案目錄路徑*/
$path = './uploads/'.date('y').'/'.date('m').'/'.date('d').'/';
//file_exists 乙個引數 判斷檔案是否存在
//is_dir 乙個引數 檢測路徑是否存在
if(!file_exists($path))
}/*移動檔案:將臨時檔案移動到指定檔案當中*/
$new_name = time().rand(0,999999999).substr($filename,strrpos($filename,'.'));
if(move_uploaded_file($filetmp,$path.$new_name))else}}
?>
php後台處理<?php
header('content-type:text/html;charset=utf8');
//include('./smarty/smarty.class.php');
include('./db.class.php');
include('./upload.class.php');
$uploads=new upload;
$filename=isset($_files['filename'])?$_files['filename']:'';
$_post['filename']=$uploads->up($filename);
$db=new db;
$res=$db->add('pictures',$_post);
if($res)else
?>
原生javascript上傳檔案外掛程式封裝
封裝函式的 function uploadfile options 建立xmlhttprequest物件 判斷在呼叫的時候有沒有傳入這兩個函式引數,防止報錯 var success options.success function var error options.error function 設...
PHP封裝成類(檔案上傳)
uploadfile.class.php created by phpstorm.user huang date 2017 7 19 time 23 20 header content type text html charset utf 8 new new upload class upload ...
PHP封裝 檔案上傳
function check file,folder uploads prefix 上傳檔案重新命名 newname uniqid prefix,true strrchr file name newdir newname 檔案拓展名驗證 info finfo open fileinfo mime t...