asmith Posted July 7, 2009 Share Posted July 7, 2009 Hi, I have this string which I wanna know what its md5_file() would be IF I save it as a file, But without having to save it actually. I have these md5_file of files in my database, I wanna know if I have that file already or not. But I don't wanna save it first. How would you do that? Quote Link to comment https://forums.phpfreaks.com/topic/165074-getting-md5_file-without-having-to-save-the-file/ Share on other sites More sharing options...
thebadbad Posted July 7, 2009 Share Posted July 7, 2009 md5('string'); ? Quote Link to comment https://forums.phpfreaks.com/topic/165074-getting-md5_file-without-having-to-save-the-file/#findComment-870455 Share on other sites More sharing options...
Psycho Posted July 7, 2009 Share Posted July 7, 2009 It's going to depend on what type of file it is. If the file is a simple txt file then md5($string) will work assuming the text is the same as in the file (i.e. linebreaks and spacing). However, other file formats don't necessarily store the data in the same way it is displayed. For example if you are trying to find what the MD5 value would be for text if it was in a word document you can't do it directly because of all the underlying code in the word file that is used to decribe how the text is displayed in addition to what text is displayed. You need to provide more details on what you are wanting to do. Quote Link to comment https://forums.phpfreaks.com/topic/165074-getting-md5_file-without-having-to-save-the-file/#findComment-870462 Share on other sites More sharing options...
asmith Posted July 7, 2009 Author Share Posted July 7, 2009 I have a database of images, Each image has its md5_file hash recorded in the MySQL too. A user is uploading his file which is actually "20 bytes + the image" (The image starts after the first 20 bytes). So I need to get the file, Cut off the first 20 bytes. Then check the result to see if there's already an image in the database. I can save it and then md5_file() the saved file and then check it against the file hashes in the MySQL. But I wanted to know if I can know the md5_hash of the image without actually having to save it. Quote Link to comment https://forums.phpfreaks.com/topic/165074-getting-md5_file-without-having-to-save-the-file/#findComment-870494 Share on other sites More sharing options...
nbarone Posted July 7, 2009 Share Posted July 7, 2009 why not save it to a temp dir then delete it if it matches? Quote Link to comment https://forums.phpfreaks.com/topic/165074-getting-md5_file-without-having-to-save-the-file/#findComment-870507 Share on other sites More sharing options...
Psycho Posted July 7, 2009 Share Posted July 7, 2009 I woud agree with nbarone. Besides, the first 20 bytes would contain the file header info (which would also be included in the files you have in your database) - so I don't see how the new files are the same as the originals except for the first 20 bytes - unless the original files don't have proper headers. Makes no sense. Quote Link to comment https://forums.phpfreaks.com/topic/165074-getting-md5_file-without-having-to-save-the-file/#findComment-870613 Share on other sites More sharing options...
asmith Posted July 8, 2009 Author Share Posted July 8, 2009 They are not images. They are generated by a software. The software makes it files by adding 20 bytes of other information to a image. So in so many cases the image is the same but the 20 byte is different. Quote Link to comment https://forums.phpfreaks.com/topic/165074-getting-md5_file-without-having-to-save-the-file/#findComment-870812 Share on other sites More sharing options...
Psycho Posted July 8, 2009 Share Posted July 8, 2009 If this is some sort of Steganography then forget about it. You are not going to be able to compare the new image with the original using MD5 or any other method without doing some sort of statistical sampling. In any case if it is exactly as you described where the forst 20 bytes really is all that is different then we have already provided a solution. Quote Link to comment https://forums.phpfreaks.com/topic/165074-getting-md5_file-without-having-to-save-the-file/#findComment-870830 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.