drebew5059 2017-03-06 09:53
浏览 102
已采纳

如何只将excel和csv文件上传到上传文件夹

i just need to grant access only to upload .csv and .xlsx files to my uploading folder. so what modifications should i do in the following coding.

<?php  if (isset($_POST["submit"])) {
    if (isset($_FILES["file"])) {
//        $_SESSION['date_ss'] = $_POST['date_ss'];
//if there was an error uploading the file
        if ($_FILES["file"]["error"] > 0) {
            echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
        } else {
            if (file_exists($_FILES["file"]["name"])) {
                unlink($_FILES["file"]["name"]);
            }

            $target_path = "uploads/";
            $target_location = $target_path . basename($_FILES['file']['name']);
            $_SESSION['target_location'] = $target_location;


//            $datess = $_POST['date_ss'];
            move_uploaded_file($_FILES["file"]["tmp_name"], $target_location);
            $uploadedStatus = 1;

        }
    } else {
        echo "No file selected <br />";
    }
}
?>
  • 写回答

1条回答 默认 最新

  • dongtan2603 2017-03-06 10:07
    关注
    $name=basename($_FILES['file']['name']);
    $name1=explode('.',$name);
    if($name1[count($name1)-1]=='csv'||$name1[count($name1)-1]=='xlsx')
    {
              $target_path = "uploads/";
            $target_location = $target_path . basename($_FILES['file']['name']);
            $_SESSION['target_location'] = $target_location;
            move_uploaded_file($_FILES["file"]["tmp_name"], $target_location);
            $uploadedStatus = 1;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据