Jump to content

getting md5_file without having to save the file


asmith

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.