read())) { if ($entry != '.' && $entry != '..') { $obj = Files::fixPath($folder).$entry; //var_dump($obj); if (is_file($obj)) { $deleted &= Files::delFile($obj); } else if(is_dir($obj)) { $deleted &= Files::delFolder($obj, $recursive); } } } $d->close(); } //$folder= $folder.'/thumbs'; //var_dump($folder); if(is_dir($folder)) $deleted &= rmdir($folder); else $deleted &= false; Return $deleted; } /** * Append a / to the path if required. * @param string $path the path * @return string path with trailing / */ function fixPath($path) { //append a slash to the path if it doesn't exists. if(!(substr($path,-1) == '/')) $path .= '/'; Return $path; } /** * Concat two paths together. Basically $pathA+$pathB * @param string $pathA path one * @param string $pathB path two * @return string a trailing slash combinded path. */ function makePath($pathA, $pathB) { $pathA = Files::fixPath($pathA); if(substr($pathB,0,1)=='/') $pathB = substr($pathB,1); Return Files::fixPath($pathA.$pathB); } /** * Similar to makePath, but the second parameter * is not only a path, it may contain say a file ending. * @param string $pathA the leading path * @param string $pathB the ending path with file * @return string combined file path. */ function makeFile($pathA, $pathB) { $pathA = Files::fixPath($pathA); if(substr($pathB,0,1)=='/') $pathB = substr($pathB,1); Return $pathA.$pathB; } /** * Format the file size, limits to Mb. * @param int $size the raw filesize * @return string formated file size. */ function formatSize($size) { if($size < 1024) return $size.' bytes'; else if($size >= 1024 && $size < 1024*1024) return sprintf('%01.2f',$size/1024.0).' KB'; else return sprintf('%01.2f',$size/(1024.0*1024)).' MB'; } /** * Returns size of a directory, with all file & subdirectory * sizes added up * @param string dir path * @return int */ function dirSize($dirName = '.') { $dir = dir($dirName); $size = 0; while ($file = $dir->read()) { if ($file != '.' && $file != '..') { if (is_dir("$dirName$file")) { $size += Files::dirSize($dirName . '/' . $file); } else { $size += filesize($dirName . '/' . $file); } } } $dir->close(); return $size; } /** * Renames file, preserving its directory and extension * @param string $oldPath path to the old existing file * @param string new filename (just the name, without path or extension) * @author Krzysztof Kotowicz */ function renameFile($oldPath, $newName) { if(!(file_exists($oldPath) && is_file($oldPath))) return FILE_ERROR_NO_SOURCE; $oldFileParts = pathinfo($oldPath); $newPath = $oldFileParts['dirname'] . '/' . $newName . (!empty($oldFileParts['extension']) ? '.' . $oldFileParts['extension'] : ''); if (file_exists($newPath)) return false; if (!rename($oldPath, $newPath)) return FILE_ERROR_COPY_FAILED; } function rename ($oldPath,$newPath) { if(!(is_dir($oldPath) || is_file($oldPath))) return FILE_ERROR_NO_SOURCE; if (file_exists($newPath)) return FILE_ERROR_DST_DIR_EXIST; $ret = rename($oldPath, $newPath); if (!$ret) return FILE_ERROR_COPY_FAILED; else return FILE_COPY_OK; } /** * copy a directory and all subdirectories and files (recursive) * @author SBoisvert at Don'tSpamMe dot Bryxal dot ca (adapted from php.net) * @author Raimund Meyer * @param string base path * @param string source directory * @param string destination directory * @param bool overwrite existing files * * @return mixed bool true on pass, number on fail */ function copyDir($basePath, $source, $dest, $overwrite = false) { if(!is_dir($basePath . $dest)) { if (!@mkdir($basePath . $dest)) return FILE_ERROR_DST_DIR_FAILED; } if($handle = opendir($basePath . $source)) { // if the folder exploration is sucsessful, continue while( ($file = readdir($handle)) !== false) { // as long as storing the next file to $file is successful, continue if($file != '.' && $file != '..') { $path = $source . '/' . $file; if(is_file($basePath . $path)) { /*if(!is_file($basePath . $dest . '/' . $file) || $overwrite) { if(!@copy($basePath . $path, $basePath . $dest . '/' . $file)) { return FILE_ERROR_COPY_FAILED; } }*/ Files::copyFile($basePath . $path, $basePath . $dest . '/', $file, true); } elseif(is_dir($basePath . $path)) { if(!is_dir($basePath . $dest . '/' . $file)) { mkdir($basePath . $dest . '/' . $file); // make subdirectory before subdirectory is copied Files::copyDir($basePath, $path, $dest . '/' . $file, $overwrite); //recurse! } } } } closedir($handle); } return true; } } ?>