laravel - hashing content of uploaded file in php -
i have upload form , dropzone file uploader beside users can upload .csv files .
i want check whether file new or not. check should contain if contents of file new or not
i store file names in database checking new files, problem when user rename same file , upload again.
my solution hashing content of each file , store beside name in database.
but don't know how hash content of .csv file in php , laravel. i've tried using
hash_file('md5' , request::file('myfilename')->getclientoriginalname());
but results in file or stream not found.
what correct way of checking new file regardless of name?
thanks in advance.
calculating hash of file correct way go.
do this:
public function uploadfile() { // check if upload valid file (example: request()->file('myfilename')->isvalid() ) // calculate hash of file $filehash = sha1_file( request()->file('myfilename')->path() ); //search file in database , block same file upload (files elequent model) if( files::where('hash', $filehash)->firstornull() != null) { abort(400); // abort upload } // file , save hash db }
Comments
Post a Comment