Rumah > pembangunan bahagian belakang > tutorial php > 我的这个文件上传 类中的input里面的name为什么不能等于数组?

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Lepaskan: 2016-06-23 14:13:46
asal
1409 orang telah melayarinya

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

谢谢 指点 已经解决了

Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan