What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » [small php request] can someone write me hash creator

Pages: (2): « First [ 1 ] 2 » Last »
[small php request] can someone write me hash creator
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
O.P. [small php request] can someone write me hash creator
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 ;)
.-= A 'frrrrrrrituurrr' for Wacky =-.
04-02-2007 12:01 PM
Profile PM Find Quote Report
Felu
Veteran Member
*****


Posts: 2223
Reputation: 72
29 / Male / Flag
Joined: Apr 2006
Status: Away
RE: [small php request] can someone write me hash creator
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.

This post was edited on 04-02-2007 at 12:22 PM by Felu.
04-02-2007 12:21 PM
Profile E-Mail PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
O.P. RE: [small php request] can someone write me hash creator
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
.-= A 'frrrrrrrituurrr' for Wacky =-.
04-02-2007 12:49 PM
Profile PM Find Quote Report
Felu
Veteran Member
*****


Posts: 2223
Reputation: 72
29 / Male / Flag
Joined: Apr 2006
Status: Away
RE: [small php request] can someone write me hash creator
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.
04-02-2007 12:51 PM
Profile E-Mail PM Web Find Quote Report
surfichris
Former Admin
*****

Avatar

Posts: 2365
Reputation: 81
Joined: Mar 2002
RE: [small php request] can someone write me hash creator
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) {
04-02-2007 12:58 PM
Profile PM Find Quote Report
Nathan
Veteran Member
*****

Avatar
Yeah, "large dimensions" ;)

Posts: 2984
Reputation: 76
– / Male / Flag
Joined: Apr 2005
RE: [small php request] can someone write me hash creator
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 :)
04-02-2007 01:15 PM
Profile E-Mail PM Web Find Quote Report
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
– / Male / –
Joined: May 2004
RE: [small php request] can someone write me hash creator
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>";

?>
04-02-2007 01:23 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
O.P. RE: [small php request] can someone write me hash creator
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.
.-= A 'frrrrrrrituurrr' for Wacky =-.
04-02-2007 01:26 PM
Profile PM Find Quote Report
Dempsey
Scripting Contest Winner
*****

Avatar
http://AdamDempsey.net

Posts: 2395
Reputation: 53
37 / Male / Flag
Joined: Jul 2003
RE: [small php request] can someone write me hash creator
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.
SoundPacks   -   Scripts   -   Skins

that's not a bug, thats an unexpected feature
04-02-2007 01:37 PM
Profile E-Mail PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
O.P. RE: [small php request] can someone write me hash creator
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...
.-= A 'frrrrrrrituurrr' for Wacky =-.
04-02-2007 02:48 PM
Profile PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On