简体   繁体   English

sha256哈希PHP,并存储在MySQL中

[英]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). 在文件上传之后,我执行了一系列相当昂贵的操作来为用户生成HTML文件(使用两个Java程序)。 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. 由于这些操作非常昂贵,因此我现在希望能够使用SHA256保留每个已上传文件的数据库。 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. 这样,如果有人上载了文件并且该文件已被处理,则无需再次处理它,而只需显示现有的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. 为了确定与文件关联的HTML是最新的,我还希望拥有两个Java程序的版本,它们在与哈希值关联的文件上运行。

So the logic goes like this: 因此逻辑如下:
1. A user submits a file. 1.用户提交文件。
2. If the file is not already on the server, business as usual. 2.如果文件尚未在服务器上,请照常进行操作。
3. If it is, check which versions of the two java programs it used to generate the html 3.如果是,请检查用于生成html的两个Java程序的版本。
4. If the current version is newer, regenerate the html. 4.如果当前版本较新,请重新生成html。

I don't know a lot about SHA or MySQL so any help would be much appreciated. 我对SHA或MySQL不太了解,因此不胜感激。 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. 真正的问题归结为:我如何在MySQL数据库上存储一堆散列值及其两个版本标识符,然后再检索该信息。

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. hash_file()可以创建文件的sha256哈希。

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} 表名称:File_Hash,列为'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). 通过这种布局,您可以将对文件的引用存储在'filepath'中,将sha256文件哈希存储在'hash'中,并标识在'engine'中使用的Java程序(第一个Java程序为1,另一个为2)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM