2017-03-06 199 views
0

我只需要授予访问权限,即只能将.csv和.xlsx文件上传到我的上传文件夹。所以我应该在下面的编码中做些什么修改。如何将excel和csv文件上传到上传文件夹

<?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 />"; 
    } 
} 
?> 

回答

0
$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; 
} 
+0

非常感谢你 –