+ Reply to Thread
Results 1 to 3 of 3

Thread: PHP Source: Check for duplicate files

  1. #1
    Code Warrior BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch's Avatar
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Age
    19
    Posts
    2,223
    Blog Entries
    8

    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

    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 11:39 AM.

  2. #2
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    Re: PHP Source: Check for duplicate files

    Pretty cool, thanks for the share! How come you didn't add comments?

  3. #3
    Code Warrior BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch's Avatar
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Age
    19
    Posts
    2,223
    Blog Entries
    8

    Re: PHP Source: Check for duplicate files

    Comments added =)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Tutorial: Storing Images in MySQL with PHP
    By Jordan in forum PHP Tutorials
    Replies: 43
    Last Post: 01-16-2010, 10:35 AM
  2. Uploading unknown number of files using php & JS
    By amrosama in forum PHP Tutorials
    Replies: 4
    Last Post: 01-08-2009, 09:48 AM
  3. Replies: 0
    Last Post: 12-14-2008, 05:20 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts