siddscool19 Posted April 25, 2009 Share Posted April 25, 2009 How to change md5 hash of a file using php? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 25, 2009 Share Posted April 25, 2009 Modify its contents... Quote Link to comment Share on other sites More sharing options...
Josso Posted June 17, 2009 Share Posted June 17, 2009 I know this post is a bit old, but it's one of the first that pops up and I think it's a fair question that needs an answer. It's easy to do it via shell, so if you have access that way, do it: <?php $file = "./file.zip"; echo "MD5 before: ".md5_file($file)."<br />\n"; system("dd if=/dev/zero ibs=1 count=1 >> ".$file); echo "MD5 after: ".md5_file($file)."<br />\n"; ?> But it's also possible to do it via "real PHP": <?php $filename = "./file.zip"; $file = fopen($filename, "a"); fwrite($file,"\n0"); fclose($file); ?> Quote Link to comment Share on other sites More sharing options...
seany123 Posted June 17, 2009 Share Posted June 17, 2009 Josso maybe you could post this in the FAQ section? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted June 17, 2009 Share Posted June 17, 2009 Because you're modifying the file, that won't work for plain text files: daniel@daniel0:~$ cat > test.php <?php echo 'Hello World' . PHP_EOL; daniel@daniel0:~$ php test.php Hello World daniel@daniel0:~$ dd if=/dev/zero ibs=1 count=1 >> test.php 1+0 records in 0+1 records out 1 byte (1 B) copied, 2,1655e-05 s, 46,2 kB/s daniel@daniel0:~$ php test.php Warning: Unexpected character in input: ' in /home/daniel/test.php on line 3 Hello World daniel@daniel0:~$ You modify it by editing the file. You could probably append a newline, that shouldn't give any problems. Do note that it's technically speaking not the same file anymore though, hence the reason why you'll get a different hash. Quote Link to comment 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.