class SyFile {
private $_upl_dir;
private $_refu_type;
private $_acce_type;
private $_errno = 0;
private $_ext;
public function __construct( $_upl_dir = '../upload', $size = 8388608 ) {
$this->_upl_dir = $_upl_dir;
if ( is_numeric( $_size ) ) @ini_set('upload_max_filesize',intval($_size));
$this->check_upload_dir();
}
/**
* set the accept file extension
* @param $acce_type;
*/
public function set_accept_type( $acce_type ) {
$this->_acce_type = $acce_type;
}
/**
* set the refuse file extension
* @param $refuse_type;
*/
public function set_refuse_type( $refuse_type ) {
$this->_refu_type = $refuse_type;
}
/**
* handing the files from the speicified file input .
* @param $name (the file input name )
* @param $over (if isn't overwrite the file)
*/
public function upload( $name,$_prefix = '', $over = true) {
$_error = $_FILES[''.$name.'']['error'];
$_local = $_FILES[''.$name.'']['name'];
$_temp = $_FILES[''.$name.'']['tmp_name'];
$_files = NULL;
$_size = count($_local);
if ( $_error != 0 ) return $_files;
$this->isLegal($_local);
if ( $this->_errno != 0 ) return $_files;
if ( $over && is_uploaded_file( $_temp ) ) {
$file = $this->generate( $_prefix );
if ( move_uploaded_file( $_temp, $this->_upl_dir.'/'.$file ) )
$_files = $file;
}
return $_files;
}
/**
* rename the new upload file
* @param $_prefix
* return the new file name;
*/
private function generate( $_prefix = '' ) {
$ret = explode(' ',microtime());
if ( $_prefix != '' ) $ret[0] = $_prefix.$ret[0];
return md5(uniqid( $ret[0],true )) . '.' .$this->_ext;;
}
/**
* check the file extension .
* @param $_name
*/
private function isLegal( $_name ) {
$_arr = explode('.',$_name);
$_size = count($_arr);
if ( $_size $this->_errno = -3;
} else {
if ( stripos( $this->_refu_type, $_arr[$_size - 1] ) !== FALSE )
$this->_errno = -1;
else if ( stripos( $this->_acce_type, $_arr[$_size - 1] ) !== FALSE )
$this->_ext = $_arr[$_size - 1];
else
$this->_errno = -2;
}
}
private function check_upload_dir() {
if ( ! file_exists( $this->_upl_dir ) ) @mkdir($this->_upl_dir);
}
public function getErrorCode() {
return $this->_errno;
}
}
这个地方写成name="upname[]" 就无法接收到input 里面的值
回复讨论(解决方案)
要这样访问 $_FILES['upname']['tmp_name'][$i]
有关php上传文件的参考文章:
php实现ftp上传下载文件的实例代码
php判断上传文件类型的代码一例
希望对你有所帮助。
谢谢 指点 已经解决了

PHP和Python各有優勢,選擇應基於項目需求。 1.PHP適合web開發,語法簡單,執行效率高。 2.Python適用於數據科學和機器學習,語法簡潔,庫豐富。

PHP不是在消亡,而是在不斷適應和進化。 1)PHP從1994年起經歷多次版本迭代,適應新技術趨勢。 2)目前廣泛應用於電子商務、內容管理系統等領域。 3)PHP8引入JIT編譯器等功能,提升性能和現代化。 4)使用OPcache和遵循PSR-12標準可優化性能和代碼質量。

PHP的未來將通過適應新技術趨勢和引入創新特性來實現:1)適應云計算、容器化和微服務架構,支持Docker和Kubernetes;2)引入JIT編譯器和枚舉類型,提升性能和數據處理效率;3)持續優化性能和推廣最佳實踐。

在PHP中,trait適用於需要方法復用但不適合使用繼承的情況。 1)trait允許在類中復用方法,避免多重繼承複雜性。 2)使用trait時需注意方法衝突,可通過insteadof和as關鍵字解決。 3)應避免過度使用trait,保持其單一職責,以優化性能和提高代碼可維護性。

依賴注入容器(DIC)是一種管理和提供對象依賴關係的工具,用於PHP項目中。 DIC的主要好處包括:1.解耦,使組件獨立,代碼易維護和測試;2.靈活性,易替換或修改依賴關係;3.可測試性,方便注入mock對象進行單元測試。

SplFixedArray在PHP中是一種固定大小的數組,適用於需要高性能和低內存使用量的場景。 1)它在創建時需指定大小,避免動態調整帶來的開銷。 2)基於C語言數組,直接操作內存,訪問速度快。 3)適合大規模數據處理和內存敏感環境,但需謹慎使用,因其大小固定。

PHP通過$\_FILES變量處理文件上傳,確保安全性的方法包括:1.檢查上傳錯誤,2.驗證文件類型和大小,3.防止文件覆蓋,4.移動文件到永久存儲位置。

JavaScript中處理空值可以使用NullCoalescingOperator(??)和NullCoalescingAssignmentOperator(??=)。 1.??返回第一個非null或非undefined的操作數。 2.??=將變量賦值為右操作數的值,但前提是該變量為null或undefined。這些操作符簡化了代碼邏輯,提高了可讀性和性能。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

Dreamweaver Mac版
視覺化網頁開發工具

記事本++7.3.1
好用且免費的程式碼編輯器