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 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题