2017-03-06 3 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

はどうもありがとうございました –

関連する問題