0

hi i'm looking for a script that gives me the md5 of a file by link i have all ready a script that gives the md5 of the files that are in the folder but now i wanna add a script where you paste the link to the file and it prints out the md5 if some one knows how to make this plz let me know

code that i have :

<?php
$cwd = $_SERVER['REQUEST_URI'];
$cwd = substr($cwd, 0, strrpos($cwd, '/' + 1));

function paintUndersideOfFox($c) {
global $cwd;
echo('<ul class="dirlist">');
$d = opendir($c);
while($f = readdir($d)) {
  if(strpos($f, '.') === 0) continue;
  $ff = $c . '/' . $f;
  echo 'MD5 file hash of ' . $ff . ': ' . md5_file($ff);
  echo('<li><a href="' . $cwd . $ff . '">' . $ff . '</a></li><br />');
  if(is_dir($ff)) paintUndersideOfFox($ff);
 }
 echo('</ul>');
}

paintUndersideOfFox('.');
?>
Nicolai
  • 133
  • 1
  • 8

2 Answers2

0

Most filesystem functions apply to streams, including HTTP. Did you try this

md5_file("http://remotelocation/file")
rakeshjain
  • 1,791
  • 11
  • 11
  • yeah i know but it must be like this, input form (here comes the url) button (to start calculating) script get the file gets the md5 after that removes file from server – Nicolai Aug 31 '13 at 11:40
  • what is the point in getting the file to your filesystem if you are anyways deleting it again after calculating the md5 of the file – rakeshjain Aug 31 '13 at 11:45
  • just a sugestion if it can calculate the md5 without downloading fine for me – Nicolai Aug 31 '13 at 11:46
  • what is the issue then. You have the url to the file from the form, just use it in the way I mentioned in my answer. – rakeshjain Aug 31 '13 at 11:50
0

Downloading files can be done via file_get_contents() or more securely with CURL

Lukas1
  • 582
  • 1
  • 5
  • 28
  • one thing to note is, that some webhosting providers block ability of file_get_contents() to download remote files, curl would work OK, though – Lukas1 Aug 31 '13 at 11:47
  • well there are many ways, actually the other suggested answer makes sense: md5_file("http://urlfromtheform.com/file"); optionally: md5(file_get_contents('http://urlfromtheform.com/file')); – Lukas1 Aug 31 '13 at 12:03
  • If for some reason you cannot use these methods (e.g. your hosting provider blocks this functionality), you may refer to this SO answer http://stackoverflow.com/questions/6409462/downloading-a-large-file-using-curl -> Btw before asking you should have tried searching SO for similar answers, there are many of them... For example: http://stackoverflow.com/questions/2304081/php-get-the-md5-of-remote-file – Lukas1 Aug 31 '13 at 12:06
  • wath i need is a pre made script – Nicolai Aug 31 '13 at 12:34