Log in

View Full Version : please help Folder scan. it Can't scan all my files in the folder of my download site



demonhellions
12-04-2013, 06:48 PM
1) Script Title:
scanner sript , mysql.class script
2) Script URL (on DD):

3) Describe problem:
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



// 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;



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 scan hug of files.

djr33
12-05-2013, 12:47 AM
1. I don't think this belongs here. Is this related to a Dynamic Drive script? I think this is a question about PHP and/or MySQL. Do you know which one you're having trouble with? We can help you by moving it to the right sub-forum.

2. What are you trying to accomplish? What's a "folder scan"? (I understand you can "scanning folders", but what specifically is the purpose?)

3. What is your experience with PHP/MySQL? Do you generally understand how the code works or did you just install it from a 3rd party website?

demonhellions
12-05-2013, 02:32 PM
1. I don't think this belongs here. Is this related to a Dynamic Drive script? I think this is a question about PHP and/or MySQL. Do you know which one you're having trouble with? We can help you by moving it to the right sub-forum.

im sorry for the wrong thread, you can now move this to correct section this is about php, again im sorry ...

2. What are you trying to accomplish? What's a "folder scan"? (I understand you can "scanning folders", but what specifically is the purpose?)

What are you trying to accomplish? im just tying to improve this folder scanner and to fix this erorr 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 it take to long to load when i run the /scan.php
sometimes it show
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.



What's a "folder scan"? folder Scan. This will scan the folders and add the new files on my database

but what specifically is the purpose? i am using (auto index scrip) this script have folder scan ,when im uploading using ftp client before the files show on my site index, it well need to scan first.

3. What is your experience with PHP/MySQL? Do you generally understand how the code works or did you just install it from a 3rd party website?
yes i just install it ,

demonhellions
12-08-2013, 05:04 PM
hello im willing to wait here everyday

djr33
12-09-2013, 03:36 AM
Honestly, this looks quite complicated. It's probably a relatively easy solution once it is clear what is wrong, but it would take a lot of work to figure out exactly what is wrong. I have now moved this to the right section so someone may see it and be able to help, but I would recommend either:
1. Learn PHP and MySQL so you can fix this yourself. (Generally, I would not recommend using PHP code unless you, very generally, understand what it does!)
2. Hire someone who can do this for you. They will need access to your server to test and fix it.

demonhellions
12-09-2013, 09:14 AM
hello djr33 can i hire someone here for free

52925293

someone told me that it can be fix by using the
RecursiveDirectoryIterator (http://www.php.net/manual/en/recursivedirectoryiterator.construct.php)
but i cant understand because this is my first time in php
i try to changes the
foreach($folder_files as $f) to

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
but it show error
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

and other share there own indexer script but i dont know how configure this script on my scanner. to match it on my database

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 ;
}
<?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.';
}

?>

djr33
12-09-2013, 05:44 PM
hello djr33 can i hire someone here for free Members here are volunteers and will help, but there is a limit to what we will do for free. If someone sees an obvious problem, I'm sure they will help. But as I said, this seems complicated, so think about considering other options.

but i cant understand because this is my first time in phpI understand. This is why I suggest hiring someone who can do this correctly and make sure everything is set up and working on your server. Or you can spend the time to learn how to do this. It's possible, but it won't be fast. Most importantly, you should be aware of what the code is doing on your server (or hire someone who you can trust to do it for you) because PHP can be very dangerous and cause major problems if it contains code you don't understand-- I strongly recommend not running code you do not understand, because it could cause security vulnerabilities, make permanent changes in the files on the server or just cause strange/unreliable behavior on the server.

Think of PHP like a car-- it's important to drive carefully: you should have a license [=experience] and understand what you're doing. Or you could hire someone to drive the car for you.

demonhellions
12-09-2013, 06:54 PM
thank you very much for the good information , maybe i just wait for the second person who wll riply to this thread and willing to help me to edit,modify or add additional fanction on my site script through accessing my server . (http://droidswap.net) with out any condition ..