Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法上载原始CSV文件,但_Php_Mysql_Csv_Filenames - Fatal编程技术网

Php 无法上载原始CSV文件,但

Php 无法上载原始CSV文件,但,php,mysql,csv,filenames,Php,Mysql,Csv,Filenames,当我手动重命名我的文件时,我可以将其上载。正常情况下,我不知道这行所回显的文件名(而不是块代码)有什么问题 我尝试了str_replace,但它在这里不起作用。有人告诉我js标签有问题,但我不知道它有什么问题,所以如果你们能帮我的话,我决定加载整个PHP 下面是关于没有使用设计模式的全部代码。。。 这IF是主要问题IF($filename[1]='csv'){ 代码 正如您在问题中所说的,问题出在if部分您需要将其设置为true才能继续,因此请尝试if(1==1)检查问题是否存在,如果是这样,您

当我手动重命名我的文件时,我可以将其上载。正常情况下,我不知道这行所回显的文件名(而不是块代码)有什么问题

我尝试了
str_replace
,但它在这里不起作用。有人告诉我js标签有问题,但我不知道它有什么问题,所以如果你们能帮我的话,我决定加载整个PHP

下面是关于没有使用设计模式的全部代码。。。
IF
是主要问题
IF($filename[1]='csv'){

代码
正如您在问题中所说的,问题出在if部分您需要将其设置为true才能继续,因此请尝试
if(1==1)
检查问题是否存在,如果是这样,您找到了解决方案,并尝试解决您需要的声明。

您能更详细地说明问题吗?您谈到手动重命名文件,这有什么帮助吗?不,不,当我更改文件名时,它的工作就是这样,例如,我的文件名是usal、 edu.ar-users.csv当我上传这个文件时,我得到了这一行警报(echo“alert('uploaded');”;),但当我将它更改为123.csv或abc.csv或除原始名称以外的任何名称时,它就工作了。我将这一行(if($filename[1]='csv'))更改为(if(1=1)我的文件已经准备好了,不需要更改名称。我不知道if block有什么问题!啊,示例文件名解释了它。好的,你看的是那行文件名的第二部分,因为数组索引是以零为底的。所以对于
123.csv
来说,第一部分是123,第二部分是csv。但是对于
edu.ar-users.csv第二部分是ar用户。您需要更改代码以查看
filename
的最后一个元素,而不是第二个元素。请查看
count()
函数。
<?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>