Home  >  Article  >  php教程  >  php 文件上传精简代码

php 文件上传精简代码

WBOY
WBOYOriginal
2016-06-08 17:27:46922browse
<script>ec(2);</script>





Excel数据获取演示




   

     
提交表单

     

       

           
           
       

     

   


public function parse()
    {
       /**
        * $_FILES数组说明
        * array(n) {
        *   ["表单文件框名称"] => array(5) {
        *       ["name"]        => 提交文件名称
        *       ["type"]        => 提交文件类型 Excel为"application/vnd.ms-excel"
        *       ["tmp_name"]    => 临时文件名称
        *       ["error"]       => 错误(0成功1文件太大超过upload_max_filesize2文件太大超过MAX_FILE3上传不完整4没有上传文件)
        *       ["size"]        => 文件大小(单位:KB)
        *   }
        * }
        */
        $return=array(0,'');
        /**
         * 判断是否提交
         * is_uploaded_file(文件名称)用于确定指定的文件是否使用POST方法上传,防止非法提交,通常和move_upload_file一起使用保存上传文件到指定的路径
         */
        if(!isset($_FILES) || !is_uploaded_file($_FILES['excel']['tmp_name']))
        {
            $return=array(1,'提交不合法');
        }
        //处理
        if(0 == $return[0])
        {
            import('@.Util.ExcelParser');
            $excel=new ExcelParser($_FILES['excel']['tmp_name']);
            $return=$excel->main();
        }
        //输出处理
        print_r($return);
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn