saileshbro's avatar

File existance check using checksum.

Hello i just wanted to have your feedback on checking the existance of the file stored in the system. I had a thought of checking the checksum of the file uploaded. Is it efficient and reliable? What are tour thoughts on this?

0 likes
3 replies
Tray2's avatar
Tray2
Best Answer
Level 74

I'm guessing you want the file to be unique.

There are several different checksums but to really make sure you need to use at least md5 or even better sha256. Be aware the bigger the file the longer time it will take to calculate the checksum.

There is a comparsion between the different hashes here

https://www.php.net/manual/en/function.hash-file.php

I suggest that you don't do it on the fly but rather use a queue job for this.

Allow the user to upload the file then store it in a temporary folder then check the hash and compare to the files table in the database and if it does not match add it and if it does delete it. Then inform the user.

saileshbro's avatar

@tray2 If I used Queue for processing the request, how would I respond with anerror message in the case of an already existing file. I am using blade for UI. is there any way? The user can navigate as the file uploading is completed but the file existence check is still in progress.

Please or to participate in this conversation.