目錄
回复讨论(解决方案)
首頁 後端開發 php教程 我的这个文件上传 类中的input里面的name为什么不能等于数组?

我的这个文件上传 类中的input里面的name为什么不能等于数组?

Jun 23, 2016 pm 02:13 PM

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判断上传文件类型的代码一例
希望对你有所帮助。

谢谢 指点 已经解决了

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

11個最佳PHP URL縮短腳本(免費和高級) 11個最佳PHP URL縮短腳本(免費和高級) Mar 03, 2025 am 10:49 AM

11個最佳PHP URL縮短腳本(免費和高級)

Instagram API簡介 Instagram API簡介 Mar 02, 2025 am 09:32 AM

Instagram API簡介

在Laravel中使用Flash會話數據 在Laravel中使用Flash會話數據 Mar 12, 2025 pm 05:08 PM

在Laravel中使用Flash會話數據

構建具有Laravel後端的React應用程序:第2部分,React 構建具有Laravel後端的React應用程序:第2部分,React Mar 04, 2025 am 09:33 AM

構建具有Laravel後端的React應用程序:第2部分,React

簡化的HTTP響應在Laravel測試中模擬了 簡化的HTTP響應在Laravel測試中模擬了 Mar 12, 2025 pm 05:09 PM

簡化的HTTP響應在Laravel測試中模擬了

php中的捲曲:如何在REST API中使用PHP捲曲擴展 php中的捲曲:如何在REST API中使用PHP捲曲擴展 Mar 14, 2025 am 11:42 AM

php中的捲曲:如何在REST API中使用PHP捲曲擴展

在Codecanyon上的12個最佳PHP聊天腳本 在Codecanyon上的12個最佳PHP聊天腳本 Mar 13, 2025 pm 12:08 PM

在Codecanyon上的12個最佳PHP聊天腳本

宣布 2025 年 PHP 形勢調查 宣布 2025 年 PHP 形勢調查 Mar 03, 2025 pm 04:20 PM

宣布 2025 年 PHP 形勢調查

See all articles