Jump to content

md5 sum help


elentz

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

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

You did a switcheroo on me! First you said your argument was a bit of data then you show us a string that is not THAT!

Oops, sorry  Been battling a head code and some of this is working through a fog.  My apologies

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.