ФТП Търсъчка (0.60) Част 2

Автор: kzteam

ФТП Търсъчка (0.60) Част 1

Втора част Сега ще създадеме fileindex.php start_playlist.php function.php и connect_db

4.fileindex.php

<?php
require_once("./config.php");
require_once("./conect_db.php");
require_once("./function.php");

set_time_limit(0);
// MAIN

$numFile = $numDir = $lastID = $FileAndDir = 0;

for($i=0; $i <= count($pat)-$arind; $i++)
{
$PATH='';
$prefile='';
$predir='';


$PATH=$pat[$i][0];
$prefile=$pat[$i][1];
$predir=$pat[$i][2];

@mysql_query("DELETE FROM dir WHERE predir = \"$predir\";");
@mysql_query("DELETE FROM file WHERE prefile = \"$prefile\";");

recursive($PATH,0);
insertIntoDB($predir,$prefile,$PATH,0);

recursive($PATH,1);
insertIntoDB($predir,$prefile,$PATH,1);


}

$file = $numFile/2;
$dir = $numDir/2;
echo "Indexing is completed:\nAll files: $file\nAll directory: $dir\n";
echo '<br><br><a href="./size/all.php">Вземи</a> инфо за категориите от базана данни';
?>

5.start_playlist.php

<?php
header("Content-type: audio/mpegurl");
$username="root";
$password="";
$databases="MySQL";
$mysql_conect="localhost";
require_once("./conect_db.php");
require_once("./function.php");
echo "#EXTM3U\n";
$server = "\Home-net\Music (G)";

$query = mysql_query("SELECT * FROM file, dir WHERE file.dirID=dir.dirID AND prefile LIKE '/FTP4' AND ext LIKE 'sound' ORDER BY `nameFile` ASC ");

while($row = mysql_fetch_array($query))
{
echo "#EXTINF:,".$row['nameFile']."\n";
echo "\\"."$server".$row['nameDir']."/".$row['nameFile']."".$row['']."\n";
}
?>

6.function.php

<?php
/////////////////////////////// FUNCTION FOR INDEXING FILES AND DIRECTORY ///////////////////////////

/* -=============== function allFiles($path) =================-
* Get all and return files from current directory (Връща като резултат всички файлове от текущата директория)
*/
function allFiles($path) {

if (!is_dir($path)) // If path is not corect then show error and stop (Ако пътя не е зададен коректно, дава грешка)
die("$path <<<<<< <b>WRONG DIRECTORY !!!</b>");
if (!@dir($path)) // If access for read/write is denied show error and stop (Ако няма права за четене на дадена директория, издава грешка)
die("<br><br> Can't open directory <b>$path</b>, access or permission is denied !!!");
$dir = dir($path);
$path = $dir->path;
while ($entry = $dir->read()) {
$isDir = "$path/$entry";
// if path is '.' or '..' then null path (Ако пътя е '.' или '..' т.е. едно ниво нагоре или главната директория тогава нулира пътя)
if (($entry != ".") && ($entry != "..")) $retAllFiles[] = $entry; };
$dir->close();
return $retAllFiles;
};
/* -=========== function translate_uri($uri) ===========-
*/
function translate_uri($uri)
//rawurlencodes $uri, but not any slashes
{
$uri = rawurlencode(str_replace('\\', '/', $uri));
return str_replace(rawurlencode('/'), '/', $uri);
}
function decodtrance_uri($uri)
{ return rawurldecode($uri);

}
/* -=========== function recursive($path) ===========-
*/




function recursive($path,$nula) {
global $numFile , $numDir, $PATH, $DirAndFile , $FileTime;
if ($nula==1) { $DirAndFile=''; $FileTime=''; $PATH='';}
$result = allFiles($path);
if (empty($result)) return;
while (list ($value, $files) = each($result)) {
if (is_dir("$path/$files")) {
$numDir++;
recursive("$path/$files",$nula);
}
else {
$numFile++;
$removePATH = str_replace($PATH, "", $path);
//$DirAndFile[$removePATH][] = "$files";
$DirAndFile[$removePATH][$files] = filesize("$path/$files");
$FileTime[$removePATH][$files] = date ("Y m d ", filemtime("$path/$files"));
//echo $FileTime[$removePATH][$files];

};
};
};

/////////////////////////////////////////// FUNCTION FOR DATABASES ////////////////////////////////////

/* -============= function insertIntoDB() ==============-
*/
function insertIntoDB($predir,$prefile,$PYT,$nula) {
global $DirAndFile, $FileTime;
if ($nula==1) { $DirAndFile=''; $FileTime='';}
static $icon_types = array(
'binary' => array('bat', 'com', 'dmg', 'dms', 'exe', 'msi',
'msp', 'pif', 'pyd', 'scr', 'so'),
'binhex' => array('hqx'),
'cd' => array('bwi', 'bws', 'bwt', 'ccd', 'cdi', 'cue','bin', 'img',
'iso', 'ISO', 'mdf', 'mds', 'nrg', 'nri', 'vcd'),
'comp' => array('cfg', 'conf', 'inf', 'ini', 'log', 'nfo', 'reg'),
'compressed' => array('7z', 'a', 'ace', 'ain', 'alz', 'amg', 'arc',
'ari', 'arj', 'bh', 'bz', 'bz2', 'cab', 'deb', 'dz', 'gz',
'io', 'ish', 'lha', 'lzh', 'lzs', 'lzw', 'lzx', 'msx', 'pak',
'rar', 'rpm', 'sar', 'sea', 'sit', 'taz', 'tbz', 'tbz2',
'tgz', 'tz', 'tzb', 'uc2', 'xxe', 'yz', 'z', 'zip', 'zoo'),
'dll' => array('386', 'db', 'dll', 'ocx', 'sdb', 'vxd'),
'doc' => array('abw', 'ans', 'chm', 'cwk', 'dif', 'doc', 'dot',
'mcw', 'msw', 'pdb', 'psw', 'rtf', 'rtx', 'sdw', 'stw', 'sxw',
'vor', 'wk4', 'wkb', 'wpd', 'wps', 'wpw', 'wri', 'wsd'),
'image' => array('adc', 'art', 'bmp', 'cgm', 'dib', 'gif', 'ico',
'ief', 'jfif', 'jif', 'jp2', 'jpc', 'jpe', 'jpeg', 'jpg', 'jpx',
'mng', 'pcx', 'png', 'psd', 'psp', 'swc', 'sxd', 'tga',
'tif', 'tiff', 'wmf', 'wpg', 'xcf', 'xif', 'yuv'),
'java' => array('class', 'jar', 'jav', 'java', 'jtk'),
'js' => array('ebs', 'js', 'jse', 'vbe', 'vbs', 'wsc', 'wsf',
'wsh'),
'key' => array('aex', 'asc', 'gpg', 'key', 'pgp', 'ppk'),
'mov' => array('amc', 'dv', 'm4v', 'mac', 'mov', 'mp4v', 'mpg4',
'pct', 'pic', 'pict', 'pnt', 'pntg', 'qpx', 'qt', 'qti',
'qtif', 'qtl', 'qtp', 'qts', 'qtx'),
'movie' => array('asf', 'asx', 'avi', 'div', 'divx', 'dvi', 'm1v',
'm2v', 'mkv', 'movie', 'mp2v', 'mpa', 'mpe', 'mpeg', 'mpg',
'mps', 'mpv', 'mpv2', 'ogm', 'ram', 'rmvb', 'rnx', 'rp', 'rv',
'vivo', 'vob', 'wmv', 'xvid'),
'pdf' => array('edn', 'fdf', 'pdf', 'pdp', 'pdx'),
'php' => array('inc', 'php', 'php3', 'php4', 'php5', 'phps',
'phtml'),
'ppt' => array('emf', 'pot', 'ppa', 'pps', 'ppt', 'sda', 'sdd',
'shw', 'sti', 'sxi'),
'ps' => array('ai', 'eps', 'ps'),
'sound' => array('aac', 'ac3', 'aif', 'aifc', 'aiff', 'ape', 'apl',
'au', 'ay', 'bonk', 'cda', 'cdda', 'cpc', 'fla', 'flac',
'gbs', 'gym', 'hes', 'iff', 'it', 'itz', 'kar', 'kss', 'la',
'lpac', 'lqt', 'm4a', 'm4p', 'mdz', '', '', 'mka',
'mo3', 'mod', 'mp+', 'mp1', 'mp2', 'mp3', 'mp4', 'mpc',
'mpm', 'mpp', 'nsf', 'oda', 'ofr', 'ogg', 'pac', 'pce',
'pcm', 'psf', 'psf2', 'ra', 'rm', 'rmi', 'rmjb', 'rmm', 'sb',
'shn', 'sid', 'snd', 'spc', 'spx', 'svx', 'tfm', 'tfmx',
'voc', 'vox', 'vqf', 'wav', 'wave', 'wma', 'wv', 'wvx', 'xa',
'xm', 'xmz'),
'tar' => array('gtar', 'tar'),
'text' => array('c', 'cc', 'cp', 'cpp', 'cxx', 'diff', 'h', 'hpp',
'hxx', 'm3u', 'md5', 'patch', 'pls', 'py', 'sfv', 'sh'),
'subtit' => array('sub', 'txt', 'srt'),

'web' => array('asa', 'asp', 'aspx', 'cfm', 'cgi', 'css', 'dhtml',
'dtd', 'grxml', 'htc', 'htm', 'html', 'htt', 'htx', 'jsp', 'lnk',
'mathml', 'mht', 'mhtml', 'perl', 'pl', 'plg', 'rss', 'shtm',
'shtml', 'stm', 'swf', 'tpl', 'wbxml', 'xht', 'xhtml', 'xml',
'xsl', 'xslt', 'xul'),
'xls' => array('csv', 'dbf', 'prn', 'pxl', 'sdc', 'slk', 'stc', 'sxc',
'xla', 'xlb', 'xlc', 'xld', 'xlr', 'xls', 'xlt', 'xlw'));

if ($nula==0) foreach($DirAndFile as $Path => $OnlyFile) {

// Insert PATH into database
$Path ="".addslashes($Path);

$insPath = "INSERT INTO dir VALUES('','$predir' , '$Path')";

mysql_query($insPath) or die(mysql_error());
$lastID = mysql_insert_id();
foreach ($OnlyFile as $FileName => $FileSize) {

$fitime = date ("Y-m-d ", filemtime(stripslashes("$PYT$Path")."/$FileName")) ;
// Insert FILENAME and FILESIZE into database
$FileName = addslashes($FileName);

//echo $fitime;
$arrext = explode(".", $FileName);
$extn=$arrext[count($arrext)-1];

foreach ($icon_types as $key => $row)
{
foreach($row as $cell)
{
if (strpos($cell, $extn) !== FALSE)
{
$kart= $key;

}
}
} //echo 'file='.$prefile;
/////
/*
if ($extn=='mp3') {echo 'mp3 ';
$tag = id3_get_tag( stripslashes("$PYT$Path")."/$FileName" );
print_r($tag);

}

///
*/
$status = 0;
if ($kart=="") {$kart="unknown";}
$insFile = "INSERT INTO file (dirID, fileID, prefile, nameFile , fileSize, ext, filetime , status)VALUES($lastID, '', '$prefile' ,'$FileName', '$FileSize','$kart', '$fitime', '$status')";
mysql_query($insFile) or die(mysql_error());
};
};
};

//////////////////////////////////// FUNCTION FOR SEARCH ///////////////////////////////////////////

/* -======= checkWords($word) =======-
*/
function checkWords($word) {
global $MIN_LENGTH_WORD, $IgnoredWord; // $IgnoredWord is array

// Clean input from '%' , '_' and spaced
$word = str_replace("%", "\%", $word);
$word= str_replace("_", "\_", $word);
// Strip whitespace from the beginning and end of a string
$word = trim($word);
// Remove space (over two) between word
$word = ereg_replace('[ ]+', ' ', $word);
// Convert to array
$word = explode(" ", $word);
$countWord = sizeof($word);
for ($i = 0; $i < ($countWord); $i++) {
if ((strlen($word[$i]) < $MIN_LENGTH_WORD) OR ($word[$i] == '\_') OR ($word[$i] == '\%'))
$IgnoredWord[] = $word[$i];
else
$ChekedWord[] = $word[$i];
};
return $ChekedWord;
};

/* -======= searchDir($word) =======-

function searchDir($word, $limit = '') {
global $MAX_WORD_SEARCH, $NUM_SHOW_FILES;

$countWord = sizeof($word);
for ($i = 0; ($i < ($countWord-1) AND ($i < $MAX_WORD_SEARCH-1)); $i++) {
$queryLike.= " nameDir LIKE '%$word[$i]%' AND";
};
$queryLike.= " nameDir LIKE '%$word[$i]%'"; // Last query not end with 'AND'!

$query = "SELECT nameDir predir ";
$query.= "FROM dir ";
$query.= "WHERE $queryLike";
if ($limit != '' ) $query.= "LIMIT $limit, $NUM_SHOW_FILES "; //LIMIT $limit, $NUM_SHOW_FILES
//echo 'ssss'.$query;
$res = mysql_query($query) or die(mysql_error());
return $res;

};

/* -======= searchFile($word) =======-
*/
function searchFile($word,$typs,$sor,$ts,$golemt,$golemv,$golemp,$sdir, $limit = '') {
global $MAX_WORD_SEARCH, $NUM_SHOW_FILES;
//$typs= $_POST['typefile'];
//echo 'sor='.$sor.',ts='.$ts;
if (($golemt=='') or ($golemp=='nula') or ($golemv=='nula')) {$qgolem="";}
else { if ($golemv=='kb') {$golemt=$golemt*1024;}
if ($golemv=='mb') {$golemt=$golemt*1048576;}
$qgolem=" AND ( '$golemt' ";
if ($golemp=='hi') {$qgolem.=" <= ";}
if ($golemp=='lo') {$qgolem.=" >= ";}
$qgolem.=" fileSize )";
//echo " ".$qgolem;


}

$qsor=" ORDER BY ";
if ($sor=="n") {$qsor.=" nameFile ";}
if ($sor=="g") {$qsor.=" fileSize ";}
if ($sor=="d") {$qsor.=" filetime ";}
if ($sor=="s") {$qsor.=" prefile ";}

if ($ts=="v") {$qsor.=" ASC ";}
if ($ts=="n") {$qsor.=" DESC ";}
//echo ' '.$qsor.' ';
if ($typs == "all") {$qtype='';}
else {$qtype= 'AND (file.ext="'.$typs.'") ';}
$psearchDIRname = $psearchDIRname123;
$countWord = sizeof($word);
for ($i = 0; ($i < ($countWord-1) AND ($i < $MAX_WORD_SEARCH-1)); $i++) {
$queryLike.= " (file.nameFile LIKE '%$word[$i]%' OR (dir.nameDir LIKE '%$word[$i]%') AND $sdir = 1) AND";
};
$queryLike.= " (file.nameFile LIKE '%$word[$i]%' OR (dir.nameDir LIKE '%$word[$i]%') AND $sdir = 1) AND"; // Last query not end with 'AND' !

$query = "SELECT file.nameFile, file.fileSize, file.ext, dir.nameDir , dir.predir, file.prefile ,file.filetime ";
$query.= "FROM file, dir ";
$query.= "WHERE $queryLike (file.dirID=dir.dirID) $qgolem $qtype $qsor ";
if ($limit != '' ) $query.= "LIMIT $limit, $NUM_SHOW_FILES ";//
//echo $query;
$res = mysql_query($query) or die(mysql_error());
return $res;
};
/* -======= size($fs) =======-
*/
function size($fs) {

// GB
if ($fs >= 1073741824) return sprintf("%2.2f GB", ($fs/1073741824));
// MB
if ($fs >= 1048576) return sprintf("%2.2f MB", ($fs/1048576));
// KB
if ($fs >= 1024) return sprintf("%2.2f KB", ($fs/1024));
// Byte
// default
return sprintf ("%d Bytes", ($fs));

};

?>

7.conect_db.php

<?php
$db = @mysql_connect($mysql_conect, $username, $password) or die("Error!!!");
@mysql_select_db($databases, $db) or die("Error!!!");
?>

След това добавяме папки
1.папка index_icons

2 папка size

Това беше 🙂

One Reply to “ФТП Търсъчка (0.60) Част 2”

Leave a Reply