0

i have to upload a file and insert the data into tables.i am done with that part. now,i want to check whether the file has been already uploaded or not. if so,alert should be thrown.

    if(isset($_POST["submit"]))
    {
    if($_FILES['file']['name'])
    {
        $filename = explode(".", $_FILES['file']['name']);
        $a=$filename[0];
        foreach($a as $b){
        if($b==$filename[0]){
                            echo"file already uploaded";
                            }
                          }
     }
   }
Anil
  • 1,087
  • 1
  • 11
  • 24
dodo
  • 18
  • 5

1 Answers1

0
             if($filename[1] == 'csv')
                                    {

                                         $fp = fopen($_FILES['file']['tmp_name'],'r') or die("can't open file");
                                         $a=$filename[0];
                                         echo $a;
                                         $query1 = $this->db->query("SELECT * from table WHERE table.filename='".$a."'");
                                         $b=$query1->num_rows();
                                         if($b>0)

                                         {
                                            echo "<script type='text/javascript'>alert('FILE ALREADY BEEN UPLOADED')</script>";
                                         }
              else{
                  }
dodo
  • 18
  • 5