Folder scan. Can't scan all my files in the foler (download site)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Folder scan. Can't scan all my files in the foler (download site)

    i have some troubles on my download site script , i have a Total Space Used: 35.18 GB, 36.751 of files, and my folder scanner did not work now. it can't scan all my files to add it on my database,now my other files are not showing even i already uploaded in my site folder, btw im uploading files using ftp client,so i need to use scanner to show it on my site index. when i try to scan it say

    error
    500 Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.
    Please contact the server administrator and inform them of the time the error occurred, and the actions you performed just before this error. More information about this error may be available in the server error log.

    or error
    Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/content/50/118050/html/lib/mysql.class.php on line 41

    im just hoping if anyone can help me here to resolved this problem,...
    heres the code

    PHP Code:
    // scan.php
    
    @set_time_limit(0); 
    
    include "../inc/init.php"; 
    
    if(!is_admin()) { 
        header("Location: $set->url");exit; 
    } 
    
    $links[] = mai_img("arr.gif")." <a href='index.php'>$lang->admincp </a>"; 
    $links[] = mai_img("arr.gif")." Scan Folders "; 
    
    $folder_count = 0; 
    $files_count = 0; 
    
    
    // grab the files 
    
    
    $db_fl = $db->select("SELECT * FROM `".MAI_PREFIX."files`"); 
    foreach($db_fl as $file) 
        $db_files[] = $file->path;  
    
    $folder_files = scaner("../files/"); 
    
    foreach($folder_files as $f){ 
        $f = rtrim($f,"/"); 
        if(!in_array($f,$db_files)){ 
            $db_files[] = $f; 
            if(is_dir("..".$f)){ 
                $dir = $db->get_row("SELECT `id` FROM `".MAI_PREFIX."files` WHERE `path`='".dirname($f)."'"); 
                $add = array( 
                "path" => $db->escape($f), 
                "name" => $db->escape(basename($f)), 
                "time" => time(), 
                "indir" => (int)$dir->id, 
                "size" => 0 
                ); 
                $db->insert_array(MAI_PREFIX."files",$add); 
                $folder_count++; 
            }else{ 
                $dir = $db->get_row("SELECT `id` FROM `".MAI_PREFIX."files` WHERE `path`='".dirname($f)."'"); 
                $add = array( 
                "path" => $db->escape($f), 
                "name" => $db->escape(basename($f)), 
                "time" => time(), 
                "indir" => (int)$dir->id, 
                "size" => filesize("..".$f) 
                ); 
                $db->insert_array(MAI_PREFIX."files",$add); 
                $files_count++; 
            } 
        } 
    } 
    
    // check for extra files 
    $tmp_files = array_map("_rtrim",$folder_files); 
    $extra = array_diff(array_merge($tmp_files, $db_files), array_intersect($tmp_files, $db_files)); 
    
    foreach($extra as $extra) 
        $db->query("DELETE FROM `".MAI_PREFIX."files` WHERE `path`='".$db->escape($extra)."'"); 
    
    
    include "../header.php"; 
    
    echo "<div class='content'>Scan Complete !<br/> 
    New folders: ".$folder_count."<br/> 
    New files: ".$files_count."<br/> 
    </div> 
    "; 
    
    include "../footer.php"; 
    
    // functions 
    function _rtrim($v){ 
        return rtrim($v,"/"); 
    } 
    
    function scaner($path) 
    { 
        static $f_arr; 
    
        @chmod($path,0777); 
    
        $arr = glob($path.'/*'); 
         
        if(is_array($arr)){ 
            foreach($arr as $vv){ 
    
                if(is_dir($vv)){ 
                    $f_arr[] = substr($vv,2).'/'; 
                    scaner($vv); 
                }else{ 
                    $f_arr[] = substr($vv,2); 
                } 
            } 
        } 
        return $f_arr; 
    
    PHP Code:
    mysql.class.php
    if(extension_loaded('mysqli')) {
        class dbConn {
            var $link = null;
    
            function __construct($db_host,$db_user,$db_pass,$db_name){
                
                $this->link = @mysqli_connect($db_host, $db_user, $db_pass, $db_name);
                
                if (!$this->link) die('Connect Error (' . mysqli_connect_errno() . ') '.mysqli_connect_error());
                
                mysqli_select_db($this->link, $db_name) or die(mysqli_error($this->link));
                
                return true;
            }
            
            function select($q){
            
                $result = mysqli_query($this->link,$q);
    
                if(mysqli_num_rows($result) > 0)
    
                    while($res = mysqli_fetch_object($result))
                    
                        $arr[] = $res;
                    
                if($arr) return $arr;
                
                return false;
            }
            function get_row($q){
                $result = mysqli_query($this->link,$q);
    
                if(mysqli_num_rows($result) == 1)
    
                $arr = mysqli_fetch_object($result);
                                
                if($arr) return $arr;
                
                return false;
            }
            function count($q){
                $result = mysqli_query($this->link,$q);
    
                return mysqli_num_rows($result);
    
            }
    
            function query($q){
    
                return mysqli_query($this->link,$q);
    
            }
    
            function escape($str){
    
                return mysqli_real_escape_string($this->link,$str);
    
            }
            function insert($q){
    
                if(mysqli_query($this->link,$q))
                    return mysqli_insert_id($this->link); 
                return false;
            }
            function insert_array($table,$array){
                $q = "INSERT INTO `$table`";
                $q .=" (`".implode("`,`",array_keys($array))."`) ";
                $q .=" VALUES ('".implode("','",array_values($array))."') ";
    
                if(mysqli_query($this->link,$q))
                    return mysqli_insert_id($this->link);
                return false;
            }
        }
    } else { // we use the old mysql
        class dbConn {
            var $link = null;
    
            function __construct($db_host,$db_user,$db_pass,$db_name){
                
                $this->link = @mysql_connect($db_host, $db_user, $db_pass);
                
                if (!$this->link) die('Connect Error (' . mysql_errno() . ') '.mysql_error());
                
                mysql_select_db($db_name, $this->link) or die(mysql_error($this->link));
                
                return true;
            }
            
            function select($q){
            
                $result = mysql_query($q, $this->link);
    
                if(mysql_num_rows($result) > 0)
    
                    while($res = mysql_fetch_object($result))
                    
                        $arr[] = $res;
                    
                if($arr) return $arr;
                
                return false;
            }
            function get_row($q){
                $result = mysql_query($q, $this->link);
    
                if(mysql_num_rows($result) == 1)
    
                $arr = mysql_fetch_object($result);
                                
                if($arr) return $arr;
                
                return false;
            }
            function count($q){
                $result = mysql_query($q, $this->link);
    
                return mysql_num_rows($result);
    
            }
    
            function query($q){
    
                return mysql_query($q, $this->link);
    
            }
    
            function escape($str){
    
                return mysql_real_escape_string($str, $this->link);
    
            }
            function insert($q){
    
                if(mysql_query($q, $this->link))
                    return mysql_insert_id($this->link);
                return false;
            }
            function insert_array($table,$array){
                $q = "INSERT INTO `$table`";
                $q .=" (`".implode("`,`",array_keys($array))."`) ";
                $q .=" VALUES ('".implode("','",array_values($array))."') ";
    
                if(mysql_query($q, $this->link))
                    return mysql_insert_id($this->link);
                return false;
            }
        }
    
    
    } 
    
    i wish you can suggest or post a code, recode,advice to run this or to make this scanner better and faster and can handle hug of files.
    Last edited by demonhellions; 05.12.13, 15:40. Reason: wrong grammar and typographical

    #2
    PHP5 is on way to resurect civilization. RecursiveDirectoryIterator PHP 5 >= 5.1.2
    Nous Ne Dansos Pas, Nous Sommes Le Danse.!

    Comment


      #3
      i cant understand ,

      Comment


        #4
        im willing to wait here to fix this problem

        Comment


          #5
          looks like you need to start from bottom.
          • learn how to use php.net
          • "how to PHP"

          in that link theres everything you need for your solution.

          PHP Code:
          foreach (new RecursiveDirectoryIterator('/your/path/') as $folder) {
               print $folder->getFilename();
           } 
          
          or if your that lazy to learn something new by yourself...
          Nous Ne Dansos Pas, Nous Sommes Le Danse.!

          Comment


            #6
            hello vaney i try your suggestion but i got an error

            PHP Code:
            // grab the files
            
            
            $db_fl = $db->select("SELECT * FROM `".MAI_PREFIX."files`");
            foreach($db_fl as $file)
                $db_files[] = $file->path; 
            
            $folder_files = scaner("../files/");
            
            foreach (new RecursiveDirectoryIterator('/') as $folder) { 
                 print $folder->getFilename();
                if(!in_array($f,$db_files)){
                    $db_files[] = $f;
                    if(is_dir("..".$f)){
                        $dir = $db->get_row("SELECT `id` FROM `".MAI_PREFIX."files` WHERE `path`='".dirname($f)."'");
                        $add = array(
                        "path" => $db->escape($f),
                        "name" => $db->escape(basename($f)),
                        "time" => time(),
                        "indir" => (int)$dir->id,
                        "size" => 0
                        );
                        $db->insert_array(MAI_PREFIX."files",$add);
                        $folder_count++;
                    }else{
                        $dir = $db->get_row("SELECT `id` FROM `".MAI_PREFIX."files` WHERE `path`='".dirname($f)."'");
                        $add = array(
                        "path" => $db->escape($f),
                        "name" => $db->escape(basename($f)),
                        "time" => time(),
                        "indir" => (int)$dir->id,
                        "size" => filesize("..".$f)
                        );
                        $db->insert_array(MAI_PREFIX."files",$add);
                        $files_count++;
                    }
                }
            }
            
            // check for extra files
            $tmp_files = array_map("_rtrim",$folder_files);
            $extra = array_diff(array_merge($tmp_files, $db_files), array_intersect($tmp_files, $db_files));
            
            foreach($extra as $extra)
                $db->query("DELETE FROM `".MAI_PREFIX."files` WHERE `path`='".$db->escape($extra)."'");
            
            
            include "../header.php";
            
            echo "<div class='content'>Scan Complete !<br/>
            New folders: ".$folder_count."<br/>
            New files: ".$files_count."<br/>
            </div>
            ";
            
            include "../footer.php";
            
            // functions
            function _rtrim($v){
                return rtrim($v,"/");
            }
            
            function scaner($path)
            {
                static $f_arr;
            
                @chmod($path,0777);
            
                $arr = glob($path.'/*');
                
                if(is_array($arr)){
                    foreach($arr as $vv){
            
                        if(is_dir($vv)){
                            $f_arr[] = substr($vv,2).'/';
                            scaner($vv);
                        }else{
                            $f_arr[] = substr($vv,2);
                        }
                    }
                }
                return $f_arr;
            } 
            

            when i run the scan.php
            proc
            Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/content/50/113050/html/lib/mysql.class.php on line 41
            tmpdatawebcgi-bin.mediarootlib64..etcbinusroptdevsbinselinuxmntt mpsrvvarlibbootsyshome

            Comment


              #7
              you have all of those files in one folder? oh, lord..
              Nous Ne Dansos Pas, Nous Sommes Le Danse.!

              Comment


                #8
                PHP Code:
                
                function recScan( $mainDir, $allData = array() )
                {
                // hide files
                $hidefiles = array(
                ".",
                "..",
                ".htaccess",
                ".htpasswd",
                "index.php",
                "php.ini",
                "error_log" ) ;
                
                //start reading directory
                $dirContent = scandir( $mainDir ) ;
                
                foreach ( $dirContent as $key => $content )
                {
                $path = $mainDir . '/' . $content ;
                
                // if is readable / file
                if ( ! in_array( $content, $hidefiles ) )
                {
                if ( is_file( $path ) && is_readable( $path ) )
                {
                $allData[] = $path ;
                }
                
                // if is readable / directory
                // Beware ! recursive scan eats ressources !
                else
                if ( is_dir( $path ) && is_readable( $path ) )
                {
                /*recursive*/
                $allData = recScan( $path, $allData ) ;
                }
                }
                }
                
                return $allData ;
                } 
                
                from my own indexer script


                PHP Code:
                
                <?php
                
                if($_GET['scan'] == 'now')
                    {
                        $allData = recScan("./content");
                
                        foreach($allData as $value)
                        { // check if the item is already indexed <>
                            $value = str_replace('./','',$value);
                            $check = mysql_fetch_array(mysql_query("SELECT * FROM portal_files WHERE path='" .
                                $value . "'"));
                
                            // if not just store it in database <this is a duplicate-check , prevents for double index>
                            if(empty($check['id']))
                            {//index file path , size , extension
                                    $path_parts = pathinfo($value);
                                $value = str_replace('./','',$value);
                                $insert = mysql_query("INSERT INTO portal_files SET path='" .
                                    mysql_real_escape_string($value) . "',
                                size='" . format_bytes(filesize("./" . $value . "")) . "', extension='".$path_parts['extension']."' ");
                            }
                
                            else
                            {
                                echo 'No new items were detected';
                
                                echo '</div>';
                                include 'footer.php';
                
                                exit;
                            }
                        }
                
                        //if everything is ok print the message
                        $count_items = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM portal_files"));
                        echo '' . $count_items[0] . ' files were indexed.';
                    } 
                
                ?>
                it was writen some time ago so dont bother about the code.

                After all this the selection from the database is made by matching path with LIKE statement .

                Hope this helps . Coding talk is the only forum were i still share codes / for free so enjoy and give some thanks .
                This is ten percent luck, twenty percent skill
                Fifteen percent concentrated power of will
                Five percent pleasure, fifty percent pain

                And a hundred percent reason to remember the name!

                Comment


                  #9
                  hi vaney yes i have all those files in one folder and sorry this is my first time on php i hope you understand

                  Click image for larger version

Name:	scan2.PNG
Views:	1
Size:	30.4 KB
ID:	110749


                  thannk you just_m3 for sharing ..

                  Comment


                    #10
                    hello dear vaney i send you a pm but your inbox is full

                    Comment


                      #11
                      hello just m3 can you help me to match the script you have to my database

                      Comment

                      Working...
                      X