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 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了