无法上传原始 CSV 文件但是

unable to upload original CSV file BUT

当我手动重命名我的文件时,我可以上传它们上传通常我不知道文件名有什么问题,这行回显而不是块代码..

我尝试了 str_replace 但它在这里不起作用有人告诉我 js 标签有问题但我没有弄清楚它有什么问题所以我决定上传整个 PHP 如果你能帮我一下

这里是完整的代码提前抱歉没有使用设计模式... IF 是主要问题 if ($filename[1] == 'csv') {

代码

<?php

$servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "uni";
///////////


//Filter data from here so we can search the exact column that we want to



    $connect = mysqli_connect($servername, $username, $password, $dbname);

        if($connect-> connect_error){
    
               die("Connection ERROR!".$connect->connect_error);
            $qy=mysqli_query($connect,"SELECT * FROM csv");
            $result= mysqli_num_rows($qy);

            printf("all data : %d",$result); 
            
      
   
            echo "<table border='1'>
                    <tr>
                    <th>email</th>
                    <th>password</th>
                    <th>Firstname</th>
                    <th>Lastname</th>
                    <th>field</th>
                    <th>country</th>

                    </tr>";
     
             
            
            
            while($row=mysqli_fetch_array($qy))
            {
                echo '<tr><td>{$row["email"]}</td><td>{$row["password"]}</td><td>{$row["firstname"]}</td><td>{$row["lastname"]}</td><td>{$row["field"]}<td>{$row["country"]}</td></td></tr>';
            }
             }

$words = array("SignInName");

       if (isset($_POST["submit"])) {
    // Count total files
    $countfiles = count($_FILES['file']['name']);
           
    // Looping all files
    for ($i = 0; $i < $countfiles; $i++) {
        if ($_FILES['file']['name'][$i]) {
            $filenametmp = $_FILES['file']['name'][$i];
            $filenametmp = rename($filenametmp,'U');
            $filename = explode(".", $filenametmp);

            if ($filename[1] == 'csv') {
               $handle = fopen($_FILES['file']['tmp_name'][$i], "r");
                $counter = 0;
                while (!feof($handle)) {
                    if ($counter === 2)
                        break;
                    $buffer = fgetcsv($handle, 5000);
                    ++$counter;
                }
                while ($data = fgetcsv($handle)) {
                    if ($data[42] == "SignInName") {
                        $item0 = mysqli_real_escape_string($connect, $data[42]);
                    }
                    $item0 = mysqli_real_escape_string($connect, $data[42]);
                    $item1 = mysqli_real_escape_string($connect, $data[32]);
                    $item2 = mysqli_real_escape_string($connect, $data[13]);
                    $item3 = mysqli_real_escape_string($connect, $data[19]);
                    $item4 = mysqli_real_escape_string($connect, $data[44]);
                    $item5 = mysqli_real_escape_string($connect, $data[5]);
                    $query = "INSERT into csv(email, password, firstname,lastname,field,country) values('$item0','$item1','$item2','$item3','$item4','$item5')";
                    mysqli_query($connect, $query);
                }
                fclose($handle);
                echo "<script>alert('uploaded');</script>";
            } else {
                echo "<script>alert('ERROR ')</script>";
            }
        }
    }
}



///




if(isset($_POST["DELETE"]))
{
    $query = "
       DELETE FROM csv
            ";
     $statement = $connect->prepare($query);
        $statement->execute();
     echo "<script>alert('DB Droped');</script>";
}

    

  
//END OF IMPORT DATA

//Exporting data



 
//end of exportingdata
    
?>

<html>
        <head>
              <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
              <title>  Tag Search</title>  
              <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
              <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tagsinput/0.8.0/bootstrap-tagsinput.css" crossorigin="anonymous">
              <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tagsinput/0.8.0/bootstrap-tagsinput-typeahead.css" />
              <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
              <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
              <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tagsinput/0.8.0/bootstrap-tagsinput.min.js" crossorigin="anonymous"></script>
            
           <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>  
           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
           <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>  
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
                      <style>
                       
body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
    background-color:cornsilk;
}

#myBtn {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 30px;
  z-index: 99;
  font-size: 18px;
  border: none;
  outline: none;
  background-color: red;
  color: white;
  cursor: pointer;
  padding: 15px;
  border-radius: 4px;
}

#myBtn:hover {
  background-color: #555;
}
                      .bootstrap-tagsinput {
                       width: 100%;
                      }
                      </style>
    </head>
 <body>
     
     <nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>                        
      </button>
      <a class="navbar-brand" href="#">upload by samad</a>
    </div>
    <div class="collapse navbar-collapse" id="zxmyNavbar">
      <ul class="nav navbar-nav">
          <li class="active"><a href="custom_import.php">A</a></li>
        <li><a href="index.php">B</a></li>
          <li><a href="index_rule.php">RULE</a></li>
        <li class="dropdown">
          <a class="dropdown-toggle" data-toggle="dropdown" href="#">Tool <span class="caret"></span></a>
          <ul class="dropdown-menu">
          
            <li><a href="https://www.google.com">google</a></li>
            <li><a href="https://gmail.com">email</a></li>
          </ul>
        </li>
          
        <li><a href="about.html">about us</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="register.html"><span class="glyphicon glyphicon-user"></span>reg</a></li>
        <li><a href="login.html"><span class="glyphicon glyphicon-log-in"></span> login</a></li>
      </ul>
    </div>
  </div>
</nav>
  
<div class="container">
  <h1 dir="rtl">A</h1>
  <h3 dir="rtl"> sample   </h3>
</div>
     
     
     
     
     <button onclick="topFunction()" id="myBtn" title="Go to top">up </button>
     <div class="container">
         <br />
            <br />
                <br />
         <h2 align="center">sample text</h2><br />
         
    <form action="export.php" method="post"><input type="submit" name="export" id="export" value="CSV Export" class="btn btn-info" /> 
         <br><br><br>
        
         <div class="form-group">
    <div class="row">
     <div class="col-md-10">
      <input type="text" name="tags" id="tags" placeholder="Enter a Tag" class="form-control" data-role="tagsinput" />
     </div>
     <div class="col-md-2">
      <button type="button" name="search" class="btn btn-primary" id="search">search </button>
     
     </div>
    </div>
   </div>
   <br />
         
         
         
         </form>
      <form method="post" enctype="multipart/form-data">
            <div align="center">  
                <label>file  CSV:</label>
    <input type="file" name="file[]" multiple accept=".csv,.xls,.xlsx" />
    <br />
       
        <input type="submit" name="submit" value="Import" class="btn btn-primary" />
      
                      
            
                  
                
                <input type="submit" name="clear" value="Clear Search Resualt" class="btn btn-success" />
                 <input type="submit" name="DELETE" value="!DELETE All DATA!" class="btn btn-danger" />
    
      <br><br><br>
   
                <br><br><br>
   
   <div class="table-responsive">
    <div align="right">
        
     <p><b> filtered record <span id="total_records"></span></b></p>
     
        
         <?php  //coounting whole record of the dataabase
         $q = "
  SELECT  * FROM csv 
 ";
          $query=mysqli_query($connect,$q);
        
            $result= mysqli_num_rows($query);
         printf("all record : %d",$result);      
        
                ?>  
                
        
    </div>
       
    <table class="table table-bordered table-striped">
     <thead>
      <tr>
       <th>email</th>
       <th>pass</th>
       <th>name</th>
       <th>lastname</th>
       <th>country</th>
       <th>field</th>
      </tr>
     </thead>
     <tbody>
     </tbody>
    </table>
   </div>
  </div>
  <div style="clear:both"></div>
  <br />
  
  <br />
  <br />
  <br />
          
          
       
 </body>
</html>


<script>
    
$(document).ready(function(){
 
 load_data();

 function load_data(query)
 {
  $.ajax({
   url:"fetch.php",
   method:"POST",
   data:{query:query},
   dataType:"json",
   success:function(data)
   {
    $('#total_records').text(data.length);
    var html = '';
    if(data.length > 0)
    {
     for(var count = 0; count < data.length; count++)
     {
      html += '<tr>';
      html += '<td>'+data[count].email+'</td>';
      html += '<td>'+data[count].password+'</td>';
      html += '<td>'+data[count].firstname+'</td>';
      html += '<td>'+data[count].lastname+'</td>';
      html += '<td>'+data[count].country+'</td>';
      html += '<td>'+data[count].field+'</td></tr>';
     }
    }
    else
    {
     html = '<tr><td colspan="5">No Data Found</td></tr>';
    }
    $('tbody').html(html);
   }
  })
 }

 $('#search').click(function(){
     
  var query = $('#tags').val();
     
  load_data(query);
 });

});
    
    
    var mybutton = document.getElementById("myBtn");

// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};

function scrollFunction() {
  if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
    mybutton.style.display = "block";
  } else {
    mybutton.style.display = "none";
  }
}

// When the user clicks on the button, scroll to the top of the document
function topFunction() {
  document.body.scrollTop = 0;
  document.documentElement.scrollTop = 0;
}
</script>
     

正如您在问题中所说,问题出在 如果部分 您需要使其为真才能继续,因此请尝试 if(1==1) 检查是否是那个问题如果是这样,您找到了解决方案并尝试解决您需要的语句。