0

0

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

php中文网

php中文网

发布时间:2016-06-23 14:13:46

|

1458人浏览过

|

来源于php中文网

原创

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

谢谢 指点 已经解决了

相关专题

更多
Word 字间距调整方法汇总
Word 字间距调整方法汇总

本专题整合了Word字间距调整方法,阅读下面的文章了解更详细操作。

2

2025.12.24

任务管理器教程
任务管理器教程

本专题整合了任务管理器相关教程,阅读下面的文章了解更多详细操作。

2

2025.12.24

AppleID格式
AppleID格式

本专题整合了AppleID相关内容,阅读专题下面的文章了解更多详细教程。

0

2025.12.24

csgo视频观看入口合集
csgo视频观看入口合集

本专题整合了csgo观看入口合集,阅读下面的文章了知道更多入口地址。

29

2025.12.24

yandex外贸入口合集
yandex外贸入口合集

本专题汇总了yandex外贸入口地址,阅读下面的文章了解更多内容。

58

2025.12.24

添加脚注通用方法
添加脚注通用方法

本专题整合了添加脚注方法合集,阅读专题下面的文章了解更多内容。

1

2025.12.24

重启电脑教程汇总
重启电脑教程汇总

本专题整合了重启电脑操作教程,阅读下面的文章了解更多详细教程。

3

2025.12.24

纸张尺寸汇总
纸张尺寸汇总

本专题整合了纸张尺寸相关内容,阅读专题下面的文章了解更多内容。

5

2025.12.24

Java Spring Boot 微服务实战
Java Spring Boot 微服务实战

本专题深入讲解 Java Spring Boot 在微服务架构中的应用,内容涵盖服务注册与发现、REST API开发、配置中心、负载均衡、熔断与限流、日志与监控。通过实际项目案例(如电商订单系统),帮助开发者掌握 从单体应用迁移到高可用微服务系统的完整流程与实战能力。

1

2025.12.24

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号