sha256 hash PHP and store on MySQL
Right now I have a website which allows users to upload a file which gets stored in a local directory on my server. After the file has been uploaded, I preform a bunch of quite expensive operations to generate an HTML file for the user (using two java programs). Because these operations are so expensive, I now want to be able to use SHA256 to keep a database of every file which has been uploaded. That way, if someone uploads a file and that file has already been processed, I don't have to process it again I can just display the existing HTML.
In order to know for sure that the HTML that is associated to a file is up to date, I would also like to have the version of two java programs which I run on the file associated with the hashed value.
So the logic goes like this:
1. A user submits a file. 2. If the file is not already on 开发者_运维百科the server, business as usual. 3. If it is, check which versions of the two java programs it used to generate the html 4. If the current version is newer, regenerate the html.I don't know a lot about SHA or MySQL so any help would be much appreciated. Really the questions boils down to this: How can I store a bunch of hashed value and its two version identifiers on a MySQL database and retrieve that information later.
If the question is unclear let me know so I can clear up confusion.
Thanks!
hash_file() can create a sha256 hash of the file.
For the db, I would imagine a table as follows
Table name: File_Hash with the columns 'id' {PK, AI, int}, 'hash' {text}, 'engine' {int}, 'filepath' {varchar}
With this layout you can store a reference to the file in 'filepath', the sha256 file hash in 'hash' and identify the java program used in 'engine' (1 for the first java program, 2 for the other).
精彩评论