界面上有一个button,单击button选择本地的csv文件,选中的同事开始往数据库插入数据,之前也可以判断一下文件的格式,请问这个怎么实现,在线等,最好有个demo给我,我本人不是学php的,临时遇到的一个项目,麻烦各位帮帮忙
有的可以发我邮箱 [email protected]php

解决方案 »

  1.   

    csv是点分结构,explode就可以了。
      

  2.   

    现成或者让别人马上写一个给你不太现实,你最好自己google
    你需要下面三样东西——上传类、读取和paser csv文件、数据库插入操作,然后自己组合
    ** 注意编码的问题
      

  3.   

    我这样写,哪里有问题啊,选中文件后点批量导入没反应
    <html>
    <head>
    <title>测试页</title>
    </head>
    <body>
    <?php  
    include "../config/dbconfig.php";
    include("dbconnect.php");
    include "function.php"; if($_POST[zhixing]=='批量导入')
    {
    $filepath = $_REQUEST['filename']; //获取表单文本框的值   
     echo ("<script>alert('文本框的值为:".$filepath."');</script>"); $file = fopen('upload/'.$filepath,"r"); //只读形式打开文件,如果大家对这些函数不清楚的可以去查下php手册   //通过while循环将文件里面的内容一列一列的存入数据库   $count = 1;   while(!feof($file) && $data = fgetcsv($file))   {     $result = array();    if($count>1 && !empty($data))    {      for($i=0;$i<3;$i++)  
         {            array_push($result,$data[$i]);     }  //利用sql语句讲文件内容存入数据库      $sql = "insert into ipfilter (ipaddress) values ('".$result[0]."')";      mysql_query($sql);  
     echo ("<script>alert('文本框的值为:".$sql."');</script>");
       }   $count++;   }   fclose($file);  ?> 
    <script>
    function chooseFile()
    {  
    var ie=navigator.appName=="Microsoft Internet Explorer" ? true : false;  
    if(ie)
    {
      document.getElementById("file").click();
      document.getElementById("filename").value=document.getElementById("file").value; 
      }
      else
       { 
       var a=document.createEvent("MouseEvents");
       a.initEvent("click", true, true);  
        document.getElementById("file").dispatchEvent(a); 
        
       } 
       }
    </script>
    <form id="form1" name="form1" method="post" action=""><input type="file" id="file" name="file" style="display:none" />
       <input type="button" name="daoru" value="选择文件" onclick="chooseFile()"  >
       <input type="text" id="filename" name="filename" style="display:none" /> 
       <input type="submit" name="zhixing" value="批量导入" />
    </form>
    </body>
    </html>
      

  4.   

    很多概念性的问题……
    html是在客户端,php是在服务器端,即使在同一台机器,也是两个过程,中间必须有“传送”
    数据库也没连接就query,往哪送呢?把上面的三个步骤拆开做吧,一个个测试
    打开一个csv文件,循环生成SQL语句,测试能否echo出来
    任选一个SQL语句,测试能否能插进数据库
    然后去下载个人家写好的上传类,做csv文件上传
    最后组合上传和数据库连接我都接触不多,帮不了你什么