Welcome Guest, Not a member yet? Register   Sign In
how to check if the file is already uploaded into database
#1

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.
Reply
#2

(This post was last modified: 08-01-2017, 07:54 AM by skunkbad.)

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB