[small php request] can someone write me hash creator |
Author: |
Message: |
CookieRevised
Elite Member
    

Posts: 15497 Reputation: 173
– / / 
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 |
|
 |
Felu
Veteran Member
    
Posts: 2223 Reputation: 72
30 / / 
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  .
This post was edited on 04-02-2007 at 12:22 PM by Felu.
|
|
04-02-2007 12:21 PM |
|
 |
CookieRevised
Elite Member
    

Posts: 15497 Reputation: 173
– / / 
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  )
EDIT: it does output an error log though... but the list is created nevertheless
.-= A 'frrrrrrrituurrr' for Wacky =-.
|
|
04-02-2007 12:49 PM |
|
 |
Felu
Veteran Member
    
Posts: 2223 Reputation: 72
30 / / 
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  ? I'll look into it after I come back, have an appointment with the Dentist.
|
|
04-02-2007 12:51 PM |
|
 |
surfichris
Former Admin
    

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 |
|
 |
Nathan
Veteran Member
    

Yeah, "large dimensions" ;)
Posts: 2978 Reputation: 76
– / / 
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 |
|
 |
Eljay
Elite Member
    

:O
Posts: 2946 Reputation: 77
– / / –
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
If something doesn't work, remember I haven't used PHP a lot for a long time thanks to the wonderful Ruby language
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 |
|
 |
CookieRevised
Elite Member
    

Posts: 15497 Reputation: 173
– / / 
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 ? 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 |
|
 |
Dempsey
Scripting Contest Winner
    

http://AdamDempsey.net
Posts: 2395 Reputation: 53
38 / / 
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?  Cos I tried installing ffmpeg yesterday and it didn't work. But that error is nothing todo with your script, you can ignore it.
|
|
04-02-2007 01:37 PM |
|
 |
CookieRevised
Elite Member
    

Posts: 15497 Reputation: 173
– / / 
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? 
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 |
|
 |
Pages: (2):
« First
[ 1 ]
2
»
Last »
|
|