Shoutbox

[small php request] can someone write me hash creator - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: [small php request] can someone write me hash creator (/showthread.php?tid=73228)

[small php request] can someone write me hash creator by CookieRevised on 04-02-2007 at 12:01 PM

Could someone write me a small php script which outputs a list of hashes (md5) for all the files in the current directory.

The list should be formatted like:

xxxx *filename.ext
xxxx *filename.ext
xxxx *filename.ext
xxxx *filename.ext
etc

where xxxx is the lowercased md5 hash and filename.ext the filename on the server.

heaps of thanks ;)


RE: [small php request] can someone write me hash creator by Felu on 04-02-2007 at 12:21 PM

code:
<?php
//Define the path as relative
$path = ".";
$dir_handle = @opendir($path) or die("Unable to open $path");
?>
<table>
<tr>
<th>MD5 hash</th>
<th>Name</th>
</tr>
<?php
//Running the loop
while ($file = readdir($dir_handle))
{
   if($file != "." && $file != ".."){
      if(!is_dir($file)){
         $md5 = md5_file($file);
     echo "<tr><td>$md5</td><td><a href='$file'>$file</a></td></tr>";
      }
   }
}
?>
</table>
<?php
//close the directory
closedir($dir_handle);
?>
Should work fine :P.
RE: [small php request] can someone write me hash creator by CookieRevised on 04-02-2007 at 12:49 PM

it works... thanks (now lets test my 1GB dir of files to see if they are uploaded properly :p)

EDIT: it does output an error log though... but the list is created nevertheless


RE: [small php request] can someone write me hash creator by Felu on 04-02-2007 at 12:51 PM

quote:
Originally posted by CookieRevised
it does output an error log though
Can you tell me what the error is :P? I'll look into it after I come back, have an appointment with the Dentist.
RE: [small php request] can someone write me hash creator by surfichris on 04-02-2007 at 12:58 PM

quote:
Originally posted by Felu
Can you tell me what the error is (Smilie)? I'll look into it after I come back, have an appointment with the Dentist.
Possibly you don't attach the path to $file.

Cookie: That means all of your hashes are bad.

Above this:
code:
if(!is_dir($file)){


Add:
code:
if(!is_dir($path."/".$file)){

(Assuming he changed the path he was using)

By the way, the way you are looping over the directory is bad. You should be using:

code:
while ($file = readdir($dir_handle)) !== false) {

RE: [small php request] can someone write me hash creator by Nathan on 04-02-2007 at 01:15 PM

I've been talking to cookie and by the looks of things he has got a outdated version of php. Because netherless felu's code works (messy it may be) on my server.

However I am transfering him  to my server so everything is fine now :)


RE: [small php request] can someone write me hash creator by Eljay on 04-02-2007 at 01:23 PM

I started this before Felu posted his code, but I got bored so I added recursive listing 8-)
If something doesn't work, remember I haven't used PHP a lot for a long time thanks to the wonderful Ruby language :P

code:
<?php

function md5_list($path, $indent=''){
  $dir = dir($path);
  $entry = $dir->read();
  while($entry !== false){
    if($entry != '..' && $entry != '.'){
      $fullPath = $path . DIRECTORY_SEPARATOR . $entry;
      if(is_dir($fullPath)){
        md5_list($fullPath, $indent . "  ");
      }
      else echo $indent . md5_file($fullPath) . ' *' . $fullPath . "\n";
    }
    $entry = $dir->read();
  }
  $dir->close();
}
echo "<pre>";
md5_list(getcwd());
echo "</pre>";

?>

RE: [small php request] can someone write me hash creator by CookieRevised on 04-02-2007 at 01:26 PM

quote:
Originally posted by Felu
quote:
Originally posted by CookieRevised
it does output an error log though
Can you tell me what the error is :P? I'll look into it after I come back, have an appointment with the Dentist.
[02-Apr-2007 08:22:05] PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions//usr/local/lib/php/extensions/no-debug-non-zts-20050922/ffmpeg.so' - /usr/local/lib/php/extensions//usr/local/lib/php/extensions/no-debug-non-zts-20050922/ffmpeg.so: cannot open shared object file: No such file or directory in Unknown on line 0
quote:
Originally posted by Chris Boulton
Cookie: That means all of your hashes are bad.
hashes are generated properly though since 99% of files have same hash as original local ones (some not.. .damn connection hickups)

PS: didn't changed the path. simply uploaded in the files dir. Nevertheless, I'll add that line, thanks.

RE: [small php request] can someone write me hash creator by Dempsey on 04-02-2007 at 01:37 PM

quote:
Originally posted by CookieRevised
[02-Apr-2007 08:22:05] PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions//usr/local/lib/php/extensions/no-debug-non-zts-20050922/ffmpeg.so' - /usr/local/lib/php/extensions//usr/local/lib/php/extensions/no-debug-non-zts-20050922/ffmpeg.so: cannot open shared object file: No such file or directory in Unknown on line 0
Is it running on my server? :S  Cos I tried installing ffmpeg yesterday  and it didn't work.  But that error is nothing todo with your script, you can ignore it.
RE: [small php request] can someone write me hash creator by CookieRevised on 04-02-2007 at 02:48 PM

quote:
Originally posted by Dempsey
quote:
Originally posted by CookieRevised
[02-Apr-2007 08:22:05] PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions//usr/local/lib/php/extensions/no-debug-non-zts-20050922/ffmpeg.so' - /usr/local/lib/php/extensions//usr/local/lib/php/extensions/no-debug-non-zts-20050922/ffmpeg.so: cannot open shared object file: No such file or directory in Unknown on line 0
Is it running on my server? :S
yep

PS [off topic]: we (nathan and me) also tried to trasnfer from server (yours) to server (nathan's). This didn't work either. It connected both (tried both WS_FTP and SmartFTP) but didn't transfer...
RE: [small php request] can someone write me hash creator by Felu on 04-02-2007 at 02:51 PM

quote:
Originally posted by Chris Boulton
By the way, the way you are looping over the directory is bad. You should be using:
code:
while ($file = readdir($dir_handle)) !== false) {

while ($file = readdir($dir_handle)) !== false)
Two '(' were and and then you close 3? Mind explaining why? And also what would !== false do :P?
quote:
Originally posted by Dempsey
But that error is nothing todo with your script, you can ignore it.
You mean to say that my code has no mistakes :P?

RE: [small php request] can someone write me hash creator by hmaster on 04-02-2007 at 03:29 PM

It should be:

code:
while (false !== ($file = readdir($handle))) {
as shown on the php.net page both the correct and wrong ways, http://uk2.php.net/readdir .
RE: [small php request] can someone write me hash creator by surfichris on 04-02-2007 at 11:37 PM

quote:
Originally posted by Felu

while ($file = readdir($dir_handle)) !== false)
Two '(' were and and then you close 3? Mind explaining why?
Typo.
quote:
Originally posted by hmaster
And also what would !== false do
Try yours, place a file called "0" in the directory along with some others and watch yours exit on that.

0 is essentially false when doing standard == checking so you need to compare at the actual level which is ===. In that case, 0 != false, 0 = 0.