Jump to content

md5 sum help


elentz
Go to solution Solved by ginerjm,

Recommended Posts

I have a md5sum txt file that might look something like this

4cf85bad582597cca7fc030ce73cdb72  A11-V2.5.3.c8fd0.fw

I want to take the hash and the file name and insert them into a MySql table as two separate entries.  How do I separate the two and get them into variables so I can insert them into my db?

 

Are there any tutorials out there that will help me?

 

Thanks

Link to comment
Share on other sites

  • Solution

There's probably more elegant ways but I would do a strpos on the string looking for a space.

 

Then I would grab the beginning part up to that position for the hash and then grab the part after that position for the filename.

 

Do a trim on each to get rid of any other chars.

 

$pos = strpos($string,' ');
$value = trim(substr($string,0,$pos));
$filename = trim(substr($string,$pos));

Link to comment
Share on other sites

Thanks for the reply.  I tried this with only getting the file location :)

<?php
$string = ("/home/PhoneFirmware/100/md5.txt");
$pos = strpos($string,' ');
$value = trim(substr($string,0,$pos));
$filename = trim(substr($string,$pos));
echo $value;
echo $filename;
?>

Alternatively if you can shoe me how I can get the file name in a directory.  There will ONLY be one file in the directory in question.  I can run the md5sum to get the value of the hash and I can get that to work the way I need it.

Link to comment
Share on other sites

Well, that's because your $string variable is this text - "/home/PhoneFirmware/100/md5.txt"

 

If you want to get content of file (not the location of file), use file_get_contents function. Your first line of code should be:

$string=file_get_contents("/home/PhoneFirmware/100/md5.txt");
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.