Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. <?php
  2.  
  3. class File {
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.     /**
  12.      * @param $path
  13.      * @return string
  14.      * calculates the files fast hash
  15.      */
  16.     public function getFhash( $path ){
  17.  
  18.         $fhash = '';
  19.  
  20.  
  21.         //GET SIZE
  22.         $size = $this->getSize( $path );
  23.  
  24.  
  25.         if( $size > 150000 ){
  26.  
  27.             $fhandle = fopen($path, "r+");
  28.             $contents = fread($fhandle, 100000 );
  29.             fclose($fhandle);
  30.  
  31.             $fhash = hash( 'md5', $contents );
  32.         }
  33.         else{
  34.  
  35.             $fhash = $this->getMd5( $path );
  36.         }
  37.  
  38.  
  39.  
  40.         $fhash = md5( $fhash . $size );
  41.  
  42.  
  43.         return $fhash;
  44.     }
  45.  
  46.  
  47.  
  48.  
  49.  
  50.     /**
  51.      * @param $path
  52.      * @return int
  53.      * gets filesize
  54.      */
  55.     public function getSize( $path ){
  56.  
  57.         $size = filesize( $path );
  58.         if( $size == false ){
  59.             $size = 0;
  60.         }
  61.  
  62.         return $size;
  63.     }
  64.  
  65.  
  66.  
  67.     /**
  68.      * @param $path
  69.      * @return string
  70.      * calculates the files md5 hash
  71.      */
  72.     public function getMd5( $path ){
  73.  
  74.         return md5_file( $path );
  75.     }
  76.  
  77.  
  78.  
  79.  
  80. }
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement