Home > php教程 > PHP源码 > uploadify+PHPExcel无刷新导入数据-完善中2

uploadify+PHPExcel无刷新导入数据-完善中2

WBOY
Release: 2016-06-16 08:39:34
Original
1144 people have browsed it
跳至 [1] [全屏预览]
<?php

if (is_uploaded_file($_FILES['studata']['tmp_name'])) {

    //判断是否为excel

//    switch ($type) {
//        case '###':
//            $okType = true;
//            break;
//    }


    //得到临时文件名
    $tmp_name = $_FILES ['studata'] ['tmp_name'];

    //获得错误信息
    $error = $_FILES['studata']['error'];

    //按照点分割文件名
    $file_types = explode(".", $_FILES ['studata'] ['name']);

    //随机数名称
    $str = date("YmdHis") . md5(uniqid(rand()));

    //得到扩展名
    $file_type = $file_types[count($file_types) - 1];

    //拼接名称及扩展名
    $file_name = $str . "." . $file_type;

    //上传文件路径
    $uploaddir = "uploads/";//设置文件保存目录 注意包含/


    /**
     * 0:文件上传成功<br/>
     * 1:超过了文件大小,在php.ini文件中设置<br/>
     * 2:超过了文件的大小MAX_FILE_SIZE选项指定的值<br/>
     * 3:文件只有部分被上传<br/>
     * 4:没有文件被上传<br/>
     * 5:上传文件大小为0
     */

    if ($error == 0) {
        //  echo "文件上传成功啦!";

        //把上传的临时文件移动到uploads目录下面

        move_uploaded_file($tmp_name, $uploaddir . $file_name);
        $rootpath = dirname(__FILE__) . "/";
        $lj = $uploaddir . $file_name;
        $updir = $rootpath . $lj;
        $data = array(
            'updir' => $updir,
        );
        echo json_encode($data);


    } elseif ($error == 1) {
        echo "超过了文件大小,在php.ini文件中设置";
    } elseif ($error == 2) {
        echo "超过了文件的大小MAX_FILE_SIZE选项指定的值";
    } elseif ($error == 3) {
        echo "文件只有部分被上传";
    } elseif ($error == 4) {
        echo "没有文件被上传";
    } else {
        echo "上传文件大小为0";
    }

}


?>
Copy after login
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template