Go Back   CodeCall Programming Forum > Software Development > Classes and Code Snippets
Register Blogs Search Today's Posts Mark Forums Read

Classes and Code Snippets Post your source code and classes here

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-05-2009, 10:48 AM
BlaineSch's Avatar
Code Warrior
 
Join Date: Apr 2009
Location: Trapped in my own little world.
Age: 19
Posts: 2,169
BlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of light
Send a message via MSN to BlaineSch
PHP Source: Check for duplicate files

I didn't make this recursive because I only needed to check one directory but it wouldn't be hard for you to edit it a bit. I just made this to check a folder for duplicate pictures. Had close to 10,000 pictures ha. I realize there are a few programs out there that can do this but I get paid by the hour

PHP Code:
<?PHP
function checkduplicates($dir) {
    if(
substr($dir, -11) != "/") {
        
//if the last character isnt a / then add it
        
$dir $dir."/";
    }
    if(
is_readable($dir)) {
        
//only continue if its readable
        
$files scandir($dir);
        foreach(
$files as $file) {
            
//loop through it
            
if(!is_dir($dir.$file) && file_exists($dir.$file)) {
                
//if its not a directory and the file exists
                
$hash md5_file($dir.$file);
                
//creates the hash
                
if(strlen($a[$hash]) != 0) {
                    
//already being used so put in duplicate array
                    
$b[$hash] = $file;
                } else {
                    
//new key first array
                    
$a[$hash] = $file;
                }
            } else {
                
//directory directory array
                
$c[] = "<a href='?q={$dir}{$file}/'>$file</a>";
            }
        }
    }
    return 
'<table>
        <tr>
            <td valign="top" class="title">Folders</td>
        </tr>
        <tr>
            <td valign="top" class="cc"><pre>'
.print_r($ctrue).'</pre></td>
        </tr>
        <tr>
            <td valign="top" class="title">Duplicates</td>
        </tr>
        <tr>
            <td valign="top" class="cc"><pre>'
.print_r($btrue).'</pre></td>
        </tr>
        <tr>
            <td valign="top" class="title">Originals</td>
        </tr>
        <tr>
            <td valign="top" class="cc"><pre>'
.print_r($atrue).'</pre></td>
        </tr>
        </table>'
;
}
//not much security so dont make this public lol
$file $_GET['q'];
if(!
is_dir($file)) {
    
//default location
    
$file "/";
}
?>
<html>
<head>
<title>File Duplicate Detector</title>
<style>
    body {
        background: #e7e7e7;
    }
    td.title {
        background: #949494;
        border-top: 1px solid black;
        border-left: 1px solid black;
        border-right: 1px solid black;
    }
    td.cc {
        background: #bebebe;
        border-left: 1px solid black;
        border-right: 1px solid black;
        border-bottom: 1px solid black;
    }
</style>
</head>
<body>
    <form method="get">
        <input style="width:350px;" type="text" name="q" value="<?=$file?>">
        <input type="submit" value="Search!">
    </form>
    Duplicate files in <?=$file?>:<br /><br />
    <?PHP
    
//calls the function
    
echo checkduplicates($file);
    
?>
</body>
</html>

Last edited by BlaineSch; 05-05-2009 at 12:39 PM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-05-2009, 11:43 AM
Jordan's Avatar
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 24,556
Jordan is a name known to allJordan is a name known to allJordan is a name known to allJordan is a name known to allJordan is a name known to allJordan is a name known to all
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan Send a message via Yahoo to Jordan
Re: PHP Source: Check for duplicate files

Pretty cool, thanks for the share! How come you didn't add comments?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-05-2009, 12:39 PM
BlaineSch's Avatar
Code Warrior
 
Join Date: Apr 2009
Location: Trapped in my own little world.
Age: 19
Posts: 2,169
BlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of light
Send a message via MSN to BlaineSch
Re: PHP Source: Check for duplicate files

Comments added =)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Storing Images in MySQL with PHP Jordan PHP Tutorials 43 01-16-2010 11:35 AM
Uploading unknown number of files using php & JS amrosama PHP Tutorials 4 01-08-2009 10:48 AM
Increase Build Process added-value with Static Analysis Kernel News 0 12-14-2008 06:20 PM


All times are GMT -5. The time now is 11:19 AM.


vBulletin v3.8.0 ©2010, Jelsoft Enterprises Ltd.


no new posts

LinkBacks Enabled by vBSEO 3.1.0