Improved speeds of dir retrieval.

This commit is contained in:
Maxim Stewart 2018-12-05 21:36:50 -06:00
parent 4d87b63366
commit 677fe2f020
2 changed files with 10 additions and 8 deletions

View File

@ -25,14 +25,14 @@ function createItem($FILE, $TYPE) {
// File or folder delition
function deleteItem($FILE) {
if (is_dir($FILE)){
if (filetype($FILE) == "dir"){
//GLOB_MARK adds a slash to directories returned
$files = glob($FILE . '*', GLOB_MARK);
foreach ($files as $file) {
deleteItem($file);
}
rmdir($FILE);
} else if (is_file($FILE)) {
} else if (filetype($FILE) == "file") {
unlink($FILE);
} else {
$message = "Server: [Error] --> Failed to delete item! Not a folder or file!";
@ -73,7 +73,7 @@ function uploadFiles($targetDir) {
// Check if file already exists
$targetFile = $targetDir . $fileName;
if (file_exists($targetFile)) {
if (is_file($targetFile)) {
if (filetype($targetFile) == "file") {
unlink($targetFile);
$message = "Server: [Warnning] --> This file already exists. Overwriting it.";
} else {

View File

@ -4,7 +4,7 @@ include_once 'serverMessanger.php';
// Start of retrieving dir data
function startListing($NEWPATH, $MERGESEASSONS, $PASSWD) {
if (is_dir($NEWPATH)) {
if (filetype($NEWPATH) == "dir") {
include_once 'lockedFolders.php';
if (checkForLock($NEWPATH, $PASSWD) == false) {
@ -28,12 +28,13 @@ function startListing($NEWPATH, $MERGESEASSONS, $PASSWD) {
// Used for recursion
function listDir(&$GeneratedXML, &$NEWPATH, &$MERGESEASSONS, &$subPath) {
$dirContents = scandir($NEWPATH);
foreach ($dirContents as $fileName) {
// $dirContents = scandir($NEWPATH);
$handle = opendir($NEWPATH);
while (false !== ($fileName = readdir($handle))) {
// Filter for . and .. items We have controls for these actions
if ($fileName !== "." && $fileName !== "..") {
$fullPath = $NEWPATH . $fileName;
if ($MERGESEASSONS == "trueHere" && is_dir($fullPath) &&
if ($MERGESEASSONS == "trueHere" && filetype($fullPath) == "dir" &&
strpos(strtolower($fileName), 'season') !== false) {
$fileName .= "/";
listDir($GeneratedXML, $fullPath, $MERGESEASSONS, $fileName);
@ -42,11 +43,12 @@ function listDir(&$GeneratedXML, &$NEWPATH, &$MERGESEASSONS, &$subPath) {
}
}
}
closedir($handle);
}
// Assign XML Markup based on file type
function processItem(&$GeneratedXML, &$fullPath, &$fileName, $subPath) {
if (is_dir($fullPath)) {
if (filetype($fullPath) == "dir") {
$GeneratedXML .= "<DIR>" . $fileName . "/</DIR>";
} elseif (preg_match('/^.*\.(mkv|avi|flv|mov|m4v|mpg|wmv|mpeg|mp4|webm)$/i', strtolower($fileName))) {
$NAMEHASH = hash('sha256', $fileName);