CodeIgniter Forums
how to check if the file is already uploaded into database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: how to check if the file is already uploaded into database (/showthread.php?tid=68587)



how to check if the file is already uploaded into database - padmalosani - 07-31-2017

Code:
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";
                           }
                         }
    }
  }
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.


RE: how to check if the file is already uploaded into database - skunkbad - 08-01-2017

While storing the file in the database, you'd have some sort of identifier that you store with it, such as a sha1 or md5 of the file contents. You'd then check if your new file upload's identifier is the same as one already in the database.

Why upload to the database? This is generally a bad idea. It's better to store a reference to the file, and just store the file on the filesystem. When I do uploads:

1) Store the absolute path to the file.
2) Store the original filename.
3) Store who uploaded it.
4) Store the date it was uploaded.
5( Store the file mime type