$db = getConnection(); try { $db->delete('entries', array('id' => $args['id'])); } catch (Exception $e) { error_status($response, $e->getMessage()); } }); $app->delete('/admin/media/{id}', function ($request, $response, $args) { $db = getConnection(); $post = $request->getParsedBody(); try { $db->delete('media', array('id' => $args['id'])); foreach (explode('|', $post['path']) as $path) { unlink($_SERVER['DOCUMENT_ROOT'] . $path); $path_parts = pathinfo($path); if (is_dir_empty($path_parts['dirname'])) { rmdir($path_parts['dirname']); } } } catch (Exception $e) { error_status($response, $e->getMessage()); } }); $app->delete('/admin/file/', function ($request, $response, $args) { try { $file = $_SERVER['DOCUMENT_ROOT'] . $request->get('file'); if (file_exists($file) && is_file($file)) { unlink($file); } else { error_status($response, 'Error: ' . $file . ' does not exist.'); }
function iterate($path) { $array_dir = @scandir($path); @asort($array_dir); foreach ($array_dir as $value) { if (is_dir($value) && strcmp($value, ".") && strcmp($value, "..")) { if (!is_dir_empty($value)) { chdir($value); parse(); iterate(getcwd(), $value); chdir(".."); } } } }
function deleteDirectory($path) { $newpath = ""; $dir = explode('/', $path); $flag = ""; ksort($dir); $newdir = $dir; foreach ($dir as $d) { $x = count($newdir); if (is_array($newdir) and $x > 1) { $newpath = implode('/', $newdir); } else { $newpath = $d; } if (is_dir($newpath)) { if (is_dir_empty($newpath)) { $y = rmdir($newpath); if ($y) { $flag .= "Dir Deleted : " . $newpath . "\n"; } else { $flag .= "Failed to Deleted: " . $newpath . "\n"; } } } if ($x > 1) { $newdir = array_pop($newdir); } } return $flag; }
<?php error_reporting(0); @ini_set('cgi.fix_pathinfo', 1); if (is_dir($_POST['directory']) && !is_dir_empty($_POST['directory'])) { echo 1; } else { echo 0; } function is_dir_empty($dir) { if (!is_readable($dir)) { return null; } $handle = opendir($dir); while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { return false; } } return true; } exit;
function readTxt2() { //อ่านค่าจาก textfile เข้า db script udp //Check if any file at the files folder $dir = "/var/www/html/web/readfile/files"; if (is_dir_empty($dir)) { echo "the folder is empty, Please upload text file before process"; die; } //end check files if ($handle = opendir('/var/www/html/web/readfile/files')) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { //test entry //echo " $entry\n"; //die($entry); //===read file to make sql $tmp_file = $entry; $i = 1; //$text[]=$entry; $handle1 = fopen("/var/www/html/web/readfile/files/" . $tmp_file, "rw"); if ($handle1) { while (($line = fgets($handle1)) !== false) { // process the line read. preg_match('/<IP>(.*?)<\\/IP>/isu', $line, $ip); // find ip preg_match('/<DATE>(.*?)<\\/DATE>/isu', $line, $date); //find time preg_match('/<BOX>(.*?)<\\/BOX>/isu', $line, $box); // find ip if (preg_match("/00000000 /", $line)) { //1 $port1 = "Off"; $port2 = "Off"; $port3 = "Off"; $port4 = "Off"; } elseif (preg_match("/00000001 /", $line)) { //2 $port1 = "On"; $port2 = "Off"; $port3 = "Off"; $port4 = "Off"; } elseif (preg_match("/00000010 /", $line)) { //3 $port1 = "Off"; $port2 = "On"; $port3 = "Off"; $port4 = "Off"; } elseif (preg_match("/00000011 /", $line)) { //4 $port1 = "On"; $port2 = "On"; $port3 = "Off"; $port4 = "Off"; } elseif (preg_match("/00000100 /", $line)) { //5 $port1 = "Off"; $port2 = "Off"; $port3 = "On"; $port3 = "On"; $port4 = "Off"; } elseif (preg_match("/00000110 /", $line)) { //7 $port1 = "Off"; $port2 = "On"; $port3 = "On"; $port4 = "Off"; } elseif (preg_match("/00000111 /", $line)) { //8 $port1 = "On"; $port2 = "On"; $port3 = "On"; $port4 = "Off"; } elseif (preg_match("/00001000 /", $line)) { //9 $port1 = "Off"; $port2 = "Off"; $port3 = "Off"; $port4 = "On"; } elseif (preg_match("/00001001 /", $line)) { //10 $port1 = "On"; $port2 = "Off"; $port3 = "Off"; $port4 = "On"; } elseif (preg_match("/00001010 /", $line)) { //11 $port1 = "Off"; $port2 = "On"; $port3 = "Off"; $port4 = "On"; } elseif (preg_match("/00001011 /", $line)) { //12 $port1 = "On"; $port2 = "On"; $port3 = "Off"; $port4 = "On"; } elseif (preg_match("/00001100 /", $line)) { //13 $port1 = "Off"; $port2 = "Off"; $port3 = "On"; $port4 = "On"; } elseif (preg_match("/00001101 /", $line)) { //14 $port1 = "On"; $port2 = "Off"; $port3 = "On"; $port4 = "On"; } elseif (preg_match("/00001110 /", $line)) { //15 $port1 = "Off"; $port2 = "On"; $port3 = "On"; $port4 = "On"; } elseif (preg_match("/00001111 /", $line)) { //16 $port1 = "On"; $port2 = "On"; $port3 = "On"; $port4 = "On"; } else { $port1 = "Time out"; $port2 = "Time out"; $port3 = "Time out"; $port4 = "Time out"; } if (preg_match("/Problem : Timed out/", $line)) { $port1 = "Time out"; $port2 = "Time out"; $port3 = "Time out"; $port4 = "Time out"; } $sql = "UPDATE `mrbs`.`box_status` SET `port1` = '{$port1}',`port2` = '{$port2}',`port3` = '{$port3}',`port4` = '{$port4}', `lastupdate` = '" . $date[1] . "' WHERE `box_status`.`ip` like '" . $ip[1] . "' "; echo $sql; //insert to table echo $line; mysql_query($sql); $i++; } //end while } else { die("cannot open the file."); // error opening the file. } //echo $tmp_file; fclose($handle1); echo "</table>"; //end read file to make sql } } closedir($handle); } //====end read dir }
} } // Delete any checked folders if (isset($_POST['deletefolder'])) { foreach ($_POST['deletefolder'] as $delthis => $val) { $safefolder = str_replace(array('../', '..\\', './', '.\\'), '', urldecode($_POST['actionfolder'][$delthis])); if ($typenow == 'image') { $delthisthumbdir = $_SESSION['tinybrowser']['docroot'] . $dirpath . $safefolder . '_thumbs/'; verify_dir($delthisthumbdir, $typenow); if (is_dir($delthisthumbdir)) { @rmdir($delthisthumbdir); } } $delthisdir = $_SESSION['tinybrowser']['docroot'] . $dirpath . $safefolder; verify_dir($delthisdir); if (file_exists($delthisdir) && is_dir_empty($delthisdir) && is_dir($delthisdir) && @rmdir($delthisdir)) { $deleteqty++; } else { $errorqty++; } if ($foldernow == urldecode($_POST['actionfolder'][$delthis])) { $foldernow = ''; $passfolder = ''; } } } // Rename any folders with changed name if (isset($_POST['renamefolder'])) { foreach ($_POST['renamefolder'] as $namethis => $newname) { $urlparts = explode('/', rtrim(urldecode($_POST['actionfolder'][$namethis]), '/')); $safefolder = str_replace(array('../', '..\\', './', '.\\'), '', urldecode($_POST['actionfolder'][$namethis]));
protected function changeprofilepic() { global $rep, $view; $data = array(); if (isset($_POST['changeprofilepic'])) { $data['uploadfile'] = NULL; if ($_FILES['picturefile']['name'] != NULL) { $usr = $_SESSION['username']; ///check error upload if ($_FILES['picturefile']['error'] > 0) { if ($_FILES['picturefile']['error'] == UPLOAD_ERR_FORM_SIZE) { $data['uploadfile'] = 'The file must not be bigger than 5mo.'; } else { $data['uploadfile'] = 'The upload failed. Please try again, if this persists, contact the admin.'; } //setup the error code } $valid_extensions = array('jpg', 'jpeg', 'gif', 'png'); $extension_upload = strtolower(substr(strrchr($_FILES['picturefile']['name'], '.'), 1)); if (!in_array($extension_upload, $valid_extensions)) { $data['uploadfile'] = 'The extension isn\'t valid. The picture must be a jpg, jpeg, gig or png file.'; //setup the error code } /// end check error upload /// check error move $uploaddir = './images/users/' . $usr . '/'; //create the directory of theprofile pic if (!is_dir($uploaddir)) { mkdir($uploaddir, 0777, true); } //give this image a random name (for multiple images) $temp = explode(".", $_FILES["picturefile"]["name"]); $newfilename = round(microtime(true)) . '.' . end($temp); $uploadfile = $uploaddir . $newfilename; if (file_exists($uploadfile)) { $data['uploadfile'] = 'Error during the upload. Please try again, if this persists, contact the admin.'; //setup the error code } elseif (!move_uploaded_file($_FILES['picturefile']['tmp_name'], $uploadfile)) { //if error moving file if (is_dir_empty($uploaddir)) { rmdir($uploaddir); } //remove the directory IF NOT EMPTY $data['uploadfile'] = 'Error during the upload. Please try again, if this persists, contact the admin.'; //setup the error code } if ($data['uploadfile'] == NULL) { if ($_SESSION['profilepic'] != 'images/users/default.jpg') { unlink($_SESSION['profilepic']); } $_SESSION['profilepic'] = $uploadfile; userModel::changepicUser($usr, $newfilename); } } else { $data['uploadfile'] = 'Please select a picture!'; } } require_once $view['manageaccount']; }
function get_directory($dir, $level = 0) { $ignore = array( 'cgi-bin', '.', '..' ); $dh = @opendir($dir); while( false !== ( $file = readdir($dh))){ if( !in_array( $file, $ignore ) ){ if(is_dir("$dir/$file")) { echo "\n$file\n"; get_directory("$dir/$file", ($level+1)); } else { //echo "$spaces $file\n"; process_file("$dir/$file"); } } } closedir( $dh ); if(is_dir_empty($dir) && $dir != "D:/wamp/www/tmp_dir") { //print "\n-= Removing $dir =-\n"; rmdir($dir); } }
contact/inquire/<?php echo $typeId; ?> " class="btn btn-primary">Inquire</a></p> </div> </div> <?php } $this->load->helper('directory'); $urls = "admin/uploads/Products/Attachments/"; foreach ($allProducts as $prod_id => $prod_name) { ?> <?php $catalogue = false; if (!is_dir_empty($urls . $prod_id)) { $catalogue = true; $map = directory_map($urls . $prod_id); } ?> <div class="row"> <input class="contentSearch" type="hidden" value="<?php echo $prod_name; ?> " /> <div class="col-md-3" style="text-align: center"> <a href="#"> <img class="img-responsive onesidedropshadow prod_img" src="<?php echo $base_url; ?> admin/uploads/products/<?php
function __dequeue_items($name, $max = MAX_DEQUEUE_COUNT) { $now_writing_id = now_name(); $item_ids = array(); foreach (glob(get_queue_file($name, '*')) as $file) { if (is_dir($file)) { continue; } if (!preg_match('~/(\\d+)\\.' . ITEMS_SUFFIX . '$~', $file, $matches)) { continue; } $item_id = intval($matches[1]); if ($item_id < $now_writing_id) { $item_ids[] = $item_id; } } sort($item_ids, SORT_NUMERIC); $output_items = array(); foreach ($item_ids as $id) { $file_name = get_queue_file($name, $id); $data_str = file_get_contents($file_name); $data_arr = explode(PHP_EOL, $data_str); while ($item_str = array_shift($data_arr)) { if ($item_str === '') { continue; } $item = json_decode($item_str, true); if (empty($item)) { continue; } $output_items[] = $item; if (count($output_items) >= $max) { if (!empty($data_arr)) { $resave_str = implode(PHP_EOL, $data_arr); file_put_contents($file_name, $resave_str); break 2; } } } unlink($file_name); } $que_dir = get_queue_dir($name); if (is_dir_empty($que_dir)) { rmdir($que_dir); } return $output_items; }
</form> </div> <?php } ?> <table class="table table-striped table-advance table-hover"> <tbody> <tr> <th>Filename</th> <th>Size</th> <th>Times downloaded*</th> <th>Action</th> </tr> <?php if (is_dir_empty("s/files/")) { ?> </table> <center> <h3>You don't have any shared files!</h3></center> <?php } if ($handle = opendir("s/files/")) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != ".." && $entry != ".DS_Store" && $entry != ".htaccess" && $entry != ".htdocs") { $sum += filesize("s/files/" . $entry); $num = $num + 1; $filesize = filesize("s/files/" . $entry); $filesize = $filesize / 1024; $filesize = $filesize / 1024; $filesize = round($filesize, 3);
if (!preg_match($pattern, $url)) { include '../templates/' . $CONF['template'] . '/header.php'; set_page_title("Teknik Git"); } if (php_sapi_name() == 'cli-server' && file_exists(substr($_SERVER['REQUEST_URI'], 1))) { return false; } if (!is_writable(__DIR__ . DIRECTORY_SEPARATOR . 'cache')) { die(sprintf('The "%s" folder must be writable for GitList to run.', __DIR__ . DIRECTORY_SEPARATOR . 'cache')); } require 'vendor/autoload.php'; $config = GitList\Config::fromFile('config.ini'); $config->set('app', 'clone_url', 'git://teknik.io/'); if ($_GET['user']) { if ($userTools->checkUsernameExists($_GET['user'])) { if (is_dir($CONF['git_repo_path'][0] . "\\u\\" . $_GET['user']) && !is_dir_empty($CONF['git_repo_path'][0] . "\\u\\" . $_GET['user'])) { $_SERVER['HTTP_X_ORIGINAL_URL'] = str_replace("/u/" . $_GET['user'], "", $_SERVER['HTTP_X_ORIGINAL_URL']); $config->set('git', 'repositories', array($CONF['git_repo_path'][0] . '\\u\\' . $_GET['user'])); $config->set('git', 'hidden', array('')); $config->set('app', 'path_prefix', '/u/' . $_GET['user']); $config->set('app', 'clone_url', 'git://teknik.io/u/' . $_GET['user'] . '/'); $app = (require 'boot.php'); $app->run(); } else { ?> <div class="row"> <div class="col-sm-12 text-center"> <h2>That user has no repositories</h2> </div> </div> <?php
/** Remove all files older than the configured expiration time (user and server) If a file is empty after this then it is deleted */ function cleanUpObsolete($user) { // Expiration time in days $expirationDaysServer = readConfiguration(CONFIG_FILE, CONFIG_KEY_TRACK_EXPIRATION_DAYS); if (isNullOrEmptyString($expirationDaysServer)) { return; } $expirationDaysUser = getConfiguration($user, CONFIG_KEY_TRACK_EXPIRATION_DAYS, true); // What is the time now? $now = time(); // Expiration time in seconds // $a = array($expirationDaysServer, 24, 60, 60); // $decayTimeServer = array_product($a) + $now; $daysInSeconds = $expirationDaysServer * 24 * 60 * 60; $decayTimeServer = $now - $daysInSeconds; // $a = array($expirationDaysUser, 24, 60, 60); // $decayTimeUser = array_product($a) + $now; $daysInSeconds = $expirationDaysUser * 24 * 60 * 60; $decayTimeUser = $now - $daysInSeconds; // Iterate through all user directories if ($handle = opendir(USER_DIR)) { while (false !== ($entry = readdir($handle))) { if ($entry == "." || $entry == "..") { continue; } $userDir = USER_DIR . DIRECTORY_SEPARATOR . $entry; if (is_dir($userDir)) { // Is this the directory of the current user? $decayTime = $decayTimeServer; if ($user == $entry) { $decayTime = $decayTimeUser; } if ($handleUserDirs = opendir($userDir)) { while (false !== ($entryUserFile = readdir($handleUserDirs))) { if ($entryUserFile == "." || $entryUserFile == "..") { continue; } $userFile = $userDir . DIRECTORY_SEPARATOR . $entryUserFile; $lastModifiedTime = filemtime($userFile); if ($lastModifiedTime <= $decayTime) { unlink($userFile); } } } closedir($handleUserDirs); // Remove the user if no file is left if (is_dir_empty($userDir)) { rmdir($userDir); } } } closedir($handle); } }
/** * Cleanup directory * * @param string $path */ function cleanup_dir($path) { if (file_exists($path) && is_dir($path)) { $files = glob("{$path}/*"); foreach ($files as $file) { if (is_file($file)) { unlink($file); } } if (is_dir_empty($path)) { rmdir($path); } } }
protected function editpost() { //$post global $rep, $view; $data = array(); if (isset($_POST['edit'])) { //we edit switch ($_POST['edit']) { case 'edit': $post_Id = isset($_POST['post_id']) ? $_POST['post_id'] : NULL; $post_title = isset($_POST['post_title']) ? $_POST['post_title'] : NULL; $post_content = isset($_POST['post_content']) ? $_POST['post_content'] : NULL; $data['uploadfile'] = NULL; //if you upload a file if ($_FILES['imagepost']['name'] != NULL) { ///check error upload if ($_FILES['imagepost']['error'] > 0) { if ($_FILES['imagepost']['error'] == UPLOAD_ERR_FORM_SIZE) { $data['uploadfile'] = 'The file must not be bigger than 5mo.'; } else { $data['uploadfile'] = 'The upload failed. Please try again, if this persists, contact the admin.'; } //setup the error code } $valid_extensions = array('jpg', 'jpeg', 'gif', 'png'); $extension_upload = strtolower(substr(strrchr($_FILES['imagepost']['name'], '.'), 1)); if (!in_array($extension_upload, $valid_extensions)) { $data['uploadfile'] = 'The extension isn\'t valid. The picture must be a jpg, jpeg, gig or png file.'; //setup the error code } /// end check error upload /// check error move $uploaddir = './images/posts/' . $post_Id . '/'; //create the directory of theprofile pic if (!is_dir($uploaddir)) { mkdir($uploaddir, 0777, true); } //give this image a random name (for multiple images) $temp = explode(".", $_FILES["imagepost"]["name"]); $newfilename = round(microtime(true)) . '.' . end($temp); $uploadfile = $uploaddir . $newfilename; if (file_exists($uploadfile)) { $data['uploadfile'] = 'Error during the upload. Please try again, if this persists, contact the admin.'; //setup the error code } elseif (!move_uploaded_file($_FILES['imagepost']['tmp_name'], $uploadfile)) { //if error moving file if (is_dir_empty($uploaddir)) { rmdir($uploaddir); } //remove the directory IF NOT EMPTY $data['uploadfile'] = 'Error during the upload. Please try again, if this persists, contact the admin.'; //setup the error code } if ($data['uploadfile'] != NULL) { $post = postModel::getPost($post_Id); require_once $view['editpost']; break; } else { imageModel::addImagePost($post_Id, $_SESSION['username'], $newfilename); } } postModel::updatePost($post_Id, $post_title, $post_content); $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'editpost/' . $post_Id; header("Location: http://{$host}{$uri}/{$extra}"); break; case 'deletepost': $post_Id = isset($_POST['post_id']) ? $_POST['post_id'] : NULL; postModel::deletePost($post_Id); $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'dashboard'; header("Location: http://{$host}{$uri}/{$extra}"); break; case 'deleteimg': $post_Id = isset($_POST['post_id']) ? $_POST['post_id'] : NULL; $img_id = isset($_POST['img_id']) ? $_POST['img_id'] : NULL; imageModel::deleteImg($img_id); $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'editpost/' . $post_Id; header("Location: http://{$host}{$uri}/{$extra}"); break; default: $data[0] = 'Unknow Error'; $data[1] = 'We couldnt handle that request'; $data[0] = '<a href="dashboard" >Dashboard</a>'; require_once $view['error']; } } else { //otherwise we show the post $postId = isset($_GET['arg1']) ? $_GET['arg1'] : NULL; if ($postId == NULL) { $data = array(); $data[0] = "We're sorry, something somewhere went wrong..."; $data[1] = "Please tell us which post you want to edit first."; require_once $view['error']; } elseif (postModel::getPost($postId) == NULL) { $data = array(); $data[0] = "We're sorry, something somewhere went wrong..."; $data[1] = "The post you're trying to edit doesn't exist!"; require_once $view['error']; } else { $post = postModel::getPost($postId); require_once $view['editpost']; } } }
if ($action == "edit") { echo $row_sponsors['sponsorURL']; } ?> " placeholder=""> <span id="helpBlock" class="help-block">Be sure to include the full website URL including the http://</span> </div> </div><!-- ./Form Group --> <div class="form-group"><!-- Form Group NOT REQUIRED Select --> <label for="contestLogo" class="col-lg-2 col-md-3 col-sm-4 col-xs-12 control-label">Logo File Name</label> <div class="col-lg-6 col-md-6 col-sm-8 col-xs-12"> <!-- Input Here --> <?php $directory = USER_IMAGES; $empty = is_dir_empty($directory); if (!$empty) { ?> <select class="selectpicker" name="sponsorImage" id="sponsorImage" data-live-search="true" data-size="10" data-width="auto"> <?php echo directory_contents_dropdown($directory, $row_sponsors['sponsorImage']); ?> </select> <?php } else { echo "<p>No images exist in the user_images directory.</p>"; } ?> <span id="helpBlock" class="help-block">If the directory is empty or a file is not on the list, use the “Upload Logo Images” button below.</span> <a class="btn btn-sm btn-primary" href="<?php echo $base_url;
</span> </div> <?php } elseif (!in_array($language, $gb_translated_lang) && !in_array($language, $gb_lang) && $language != "") { ?> <div class="message red" style="display: block;margin-top:30px"> <span style="padding: 4px 0;"> <strong><p style="font:12px/1.0em Arial !important;">If you would like to translate Gallery Bank in your native language, we will reward you with a free Pro Version License of Gallery Bank worth 18£.</p> <p style="font:12px/1.0em Arial !important;">Contact Us at <a target="_blank" href="http://tech-banker.com">http://tech-banker.com</a> or email us at <a href="mailto:support@tech-banker.com">support@tech-banker.com</a></p> </strong> </span> </div> <?php } if (!is_dir(GALLERY_MAIN_THUMB_DIR)) { if (!is_dir_empty(GALLERY_MAIN_THUMB_DIR)) { ?> <div class="message red" style="display: block;margin-top:15px"> <span> <strong>If you are getting problems with thumbnails, then you need to set 777(write) permissions to <?php echo GALLERY_MAIN_DIR; ?> (recursive files & directories) in order to save the images/thumbnails. </strong> </span> </div> <?php } } function is_dir_empty($dir) { if (!is_readable($dir)) {
public function fileexplorerTreeAction() { $this->checkPermission("fileexplorer"); $referencePath = $this->getFileexplorerPath("node"); $items = scandir($referencePath); $contents = []; foreach ($items as $item) { if ($item == "." || $item == "..") { continue; } $file = $referencePath . "/" . $item; $file = str_replace("//", "/", $file); if (is_dir($file) || is_file($file)) { $itemConfig = ["id" => "/fileexplorer" . str_replace(PIMCORE_DOCUMENT_ROOT, "", $file), "text" => $item, "leaf" => true, "writeable" => is_writable($file)]; if (is_dir($file)) { $itemConfig["leaf"] = false; $itemConfig["type"] = "folder"; if (\Pimcore\Tool\Admin::isExtJS6() && is_dir_empty($file)) { $itemConfig["loaded"] = true; } $itemConfig["expandable"] = true; } elseif (is_file($file)) { $itemConfig["type"] = "file"; } $contents[] = $itemConfig; } } $this->_helper->json($contents); }
function readTxt() { //อ่านค่าจาก textfile เข้า db //Check if any file at the files folder $dir = "/var/www/html/web/readfile/files"; if (is_dir_empty($dir)) { echo "the folder is empty, Please upload text file before process"; die; } //end check files if ($handle = opendir('/var/www/html/web/readfile/files')) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { //test entry //echo " $entry\n"; //die($entry); //===read file to make sql $tmp_file = $entry; $i = 1; //$text[]=$entry; $handle1 = fopen("/var/www/html/web/readfile/files/" . $tmp_file, "rw"); if ($handle1) { while (($line = fgets($handle1)) !== false) { // process the line read. //$ip = substr($line, 24, 12); //$ip = preg_match('<IP>(.+?)"</IP>',$line,$tmpip); preg_match('/<IP>(.*?)<\\/IP>/isu', $line, $ip); preg_match('/<DATE>(.*?)<\\/DATE>/isu', $line, $date); preg_match('/<BOX>(.*?)<\\/BOX>/isu', $line, $box); //$ip = $tip; //print_r($ip); //$date = substr($line, 50, 10); //$time = substr($line, 61, 8); if (preg_match("/1<\\/a> OFF/", $line)) { $port1 = "Off"; } elseif (preg_match("/1<\\/a> <font/", $line)) { $port1 = "On"; } else { $port1 = "Fail"; } if (preg_match("/2<\\/a> OFF/", $line)) { $port2 = "Off"; } elseif (preg_match("/2<\\/a> <font/", $line)) { $port2 = "On"; } else { $port2 = "Fail"; } if (preg_match("/3<\\/a> OFF/", $line)) { $port3 = "Off"; } elseif (preg_match("/3<\\/a> <font/", $line)) { $port3 = "On"; } else { $port3 = "Fail"; } if (preg_match("/4<\\/a> OFF/", $line)) { $port4 = "Off"; } elseif (preg_match("/4<\\/a> <font/", $line)) { $port4 = "On"; } else { $port4 = "Fail"; } //$timestamp = mktime(substr($line,19,2),substr($line,21,2),0,substr($line, 14, 2),substr($line, 16, 2),substr($line, 12, 2)); //$finger = substr($line, 24, 2); //echo "Record ".$i." ".$ip[1]." Date-time ".$date[1]." Port 1 :".$port1." Port 2 :".$port2." Port 3 :".$port3." Port 4 :".$port4."<br>"; //show insert data //echo "<tr><td>$i</td><td>$staffid</td><td>$date</td><td>$time</td><td>$finger ".mktime(substr($line,19,2),substr($line,21,2),0,substr($line, 14, 2),substr($line, 16, 2),substr($line, 12, 2))."haha</td></tr>"; //end show insert data /* //query to check if any data in the same date $sql = "select * from `time`.`time` where `staffid` LIKE '$staffid' and `date` = '$date' "; $result = mysql_query($sql); if ($num = mysql_num_rows($result) != 0){ while ($rec=mysql_fetch_array($result)){ if($rec['timeIn']<$time) {// ถ้าเวลาใน txt น้อยกว่าใน DB $timeIn = $time; //ส่งค่าเวลาไปแทนที่ตัวแปร timeIn $timeOut = $rec['timeIn']; //ค่า Timeout = timein //echo "5555"; } elseif($rec['timeIn']==$time){ $sql=""; //echo "7777"; } else{ $timeOut = $time; $timeIn = $rec['timeIn']; //echo "6666"; } $sql = "update `time`.`time` set `timeIn` = '$timeIn',`timeOut` ='$timeOut' where `time`.`staffid` = '".$rec['staffId']."' and `time`.`date` = '".$rec['date']."';"; //echo $sql; //die(); } } else{ $timeIn = $time; $timeOut = ""; $sql = "INSERT INTO `time`.`time` (`id`, `staffId`, `date`, `timeIn`,`timeOut`, `machine`) VALUES (NULL, '$staffid', '$date', '$timeIn','$timeOut', '$finger');"; } //end query check date */ $sql = "UPDATE `mrbs`.`box_status` SET `port1` = '{$port1}',`port2` = '{$port2}',`port3` = '{$port3}',`port4` = '{$port4}', `lastupdate` = '" . $date[1] . "' WHERE `box_status`.`ip` like '" . $ip[1] . "' "; //$sql = "INSERT INTO `time`.`time` (`id`, `staffId`, `date`, `time`, `machine`,`timestamp`) VALUES (NULL, '$staffid', '$date', '$time', '$finger','$timestamp');"; echo $sql; //insert to table mysql_query($sql); $i++; } //end while } else { die("cannot open the file."); // error opening the file. } //echo $tmp_file; fclose($handle1); echo "</table>"; //end read file to make sql } } closedir($handle); } //====end read dir }
/** * @throws \Exception */ function move_files() { function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir . "/" . $object) == "dir") { rrmdir($dir . "/" . $object); } else { unlink($dir . "/" . $object); } } } reset($objects); rmdir($dir); } } function is_dir_empty($dir) { if (!is_readable($dir)) { return NULL; } return count(scandir($dir)) == 2; } $base_laws = DOWNLOADS_PATH . 'zakon.rada.gov.ua/laws/'; $dirs = array_merge(glob($base_laws . 'show/*/*', GLOB_ONLYDIR | GLOB_MARK), glob($base_laws . 'show/*', GLOB_ONLYDIR | GLOB_MARK)); foreach ($dirs as $dir) { if (glob($dir . '*', GLOB_ONLYDIR)) { continue; } if (glob($dir . 'card.html')) { continue; } rrmdir($dir); } $base_laws = DOWNLOADS_PATH . 'zakon.rada.gov.ua/laws/'; $files = array_merge(glob($base_laws . 'show/*/*/card.html'), glob($base_laws . 'show/*/card.html')); foreach ($files as $file) { $law_id = preg_replace('|' . $base_laws . 'show/(.*?)/card.html|', '$1', $file); $new_name_card = $base_laws . 'card/' . $law_id . '.html'; preg_match('|<span style="color: #.*?">(.*?)</span>(?:</b></a>\\n<img src="http://zakonst.rada.gov.ua/images/docs.gif" title="Документ"> <span class="num" style="color:#999999">поточна редакція, .*?, <a href=".*">перейти »</a></span>)?</dt>\\n<dd><a name="Current">|', file_get_contents($file), $matches); $revision = isset($matches[1]) ? $matches[1] : null; if ($revision) { if (!preg_match('|[0-9]{2}\\.[0-9]{2}\\.[0-9]{4}|', $revision) || !date_create_from_format('d.m.Y', $revision)) { throw new \Exception("Revision has not been found in #{$file}."); } $date = date_format(date_create_from_format('d.m.Y', $revision), 'Ymd'); $new_name_text = $base_laws . 'show/' . $law_id . '/ed' . $date . '/page.html'; $old_files = []; $text = ''; if (file_exists($base_laws . 'show/' . $law_id . '/text.html')) { $text_file_name = $base_laws . 'show/' . $law_id . '/text.html'; $old_files[] = $text_file_name; $text = crawler(file_get_contents($text_file_name))->filter('.txt')->html(); } elseif (file_exists($base_laws . 'show/' . $law_id . '/page.html')) { $text_file_name = $base_laws . 'show/' . $law_id . '/page.html'; $old_files[] = $text_file_name; $page = crawler(file_get_contents($base_laws . 'show/' . $law_id . '/page.html')); $text = $page->filter('.txt')->html(); $pager = $page->filterXPath('(//span[@class="nums"])[1]/br/preceding-sibling::a[1]'); $page_count = $pager->count() ? $pager->text() : 1; for ($i = 2; $i <= $page_count; $i++) { $text_file_name = $base_laws . 'show/' . $law_id . '/page' . $i . '.html'; if (!file_exists($text_file_name)) { $text = ''; foreach ($old_files as $file_name) { unlink($file_name); } break; } $old_files[] = $text_file_name; $page = crawler(file_get_contents($text_file_name)); $text .= $page->filter('.txt')->html(); } } if (file_exists($new_name_text)) { foreach ($old_files as $file_name) { unlink($file_name); } } elseif ($text) { $new_dir = dirname($new_name_text); if (!is_dir($new_dir)) { mkdir($new_dir, 0777, true); } file_put_contents($new_name_text, '<html><body><div class="txt txt-old">' . $text . '</div></body></html>'); touch($new_name_text, filemtime($old_files[0])); foreach ($old_files as $file_name) { unlink($file_name); } } } if (file_exists($new_name_card)) { unlink($file); } else { $new_dir = dirname($new_name_card); if (!is_dir($new_dir)) { mkdir($new_dir, 0777, true); } rename($file, $new_name_card); } if (is_dir_empty($base_laws . 'show/' . $law_id)) { rrmdir($base_laws . 'show/' . $law_id); $parent = dirname($base_laws . 'show/' . $law_id); if (is_dir_empty($parent)) { rrmdir($parent); } } } }
<?php /* * Copyright (C) 2013 RWW.IO * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ require_once 'runtime.php'; $acc = urldecode($_REQUEST['domain']); $domain = $_ENV['CLOUD_DATA'] . '/' . $acc; $empty = is_dir_empty($domain); if ($empty == true) { httpStatusExit(404, 'Not Found'); } else { httpStatusExit(200, 'OK'); } exit;
private function _cleanUpDirOld($file_id) { $path = $this->_idToPathOld($file_id); if (!$path) { return; } $path_parts = explode('/', $path); $repository_path = with_slash($this->getRepositoryDir()); $for_cleaning = array($repository_path . $path_parts[0] . '/' . $path_parts[1] . '/' . $path_parts[2], $repository_path . $path_parts[0] . '/' . $path_parts[1], $repository_path . $path_parts[0]); // array foreach ($for_cleaning as $dir) { if (is_dir_empty($dir)) { delete_dir($dir); } else { return; // break, not empty } // if } // foreach }
} $handle = opendir($dir); while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { return FALSE; } } return TRUE; } if (!empty($orderedDate)) { foreach ($orderedDate as $id => $date5) { ?> <?php $catalogue = false; if (!is_dir_empty($urls . $eventAll[$id]['readmore'])) { $catalogue = true; $map = directory_map($urls . $eventAll[$id]['readmore']); } ?> <div class="row"> <div class="col-md-3" style="text-align:center"> <a href="#"> <img class="img-responsive onesidedropshadow prod_img" src="<?php echo $base_url; ?> admin/uploads/Newsevents/<?php echo $eventAll[$id]['img']; ?> .jpg"/>
function readTxt2() { //อ่านค่าจาก textfile เข้า db //Check if any file at the files folder //$dir = "/var/www/html/time/files"; $dir = "C:\\wamp\\www\time\files"; if (is_dir_empty($dir)) { echo "the folder is empty, Please upload text file before process"; die; } //end check files if ($handle = opendir('./files')) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { //test entry echo "{$entry}\n"; //die($entry); //===read file to make sql $tmp_file = $entry; $i = 0; //$text[]=$entry; //$handle1 = fopen("/var/www/html/time/files/".$tmp_file, "rw"); $handle1 = fopen("C:\\wamp\\www\\time\\files\\" . $tmp_file, "rw"); echo "C:\\wamp\\www\\time\\files\\" . $tmp_file; echo "<table border ='1'>"; echo "<tr><th>Number</th><th>Staff ID</th><th>Date</th><th>Time</th><th>Finger</th></tr>"; if ($handle1) { while (($line = fgets($handle1)) !== false) { // process the line read. $staffid = substr($line, 0, 10); $date = substr($line, 12, 2) . "-" . substr($line, 14, 2) . "-" . substr($line, 16, 2); $time = substr($line, 19, 2) . ":" . substr($line, 21, 2) . ":00"; $timestamp = mktime(substr($line, 19, 2), substr($line, 21, 2), 0, substr($line, 14, 2), substr($line, 16, 2), substr($line, 12, 2)); $finger = substr($line, 24, 2); //show insert data //echo "<tr><td>$i</td><td>$staffid</td><td>$date</td><td>$time</td><td>$finger ".mktime(substr($line,19,2),substr($line,21,2),0,substr($line, 14, 2),substr($line, 16, 2),substr($line, 12, 2))."haha</td></tr>"; //end show insert data //query to check if any data in the same date $sql = "select * from `time`.`time` where `staffid` LIKE '{$staffid}' and `date` = '{$date}' "; echo $sql; $result = mysql_query($sql); if ($num = mysql_num_rows($result) != 0) { while ($rec = mysql_fetch_array($result)) { if ($rec['timeIn'] > $time) { // ถ้าเวลาใน txt น้อยกว่าใน DB $timeIn = $time; //ส่งค่าเวลาไปแทนที่ตัวแปร timeIn $timeOut = $rec['timeIn']; //ค่า Timeout = timein //echo "5555"; } elseif ($rec['timeIn'] == $time) { $sql = ""; //echo "7777"; } else { $timeOut = $time; $timeIn = $rec['timeIn']; //echo "6666"; } $sql = "update `time`.`time` set `timeIn` = '{$timeIn}',`timeOut` ='{$timeOut}' where `time`.`staffid` = '" . $rec['staffId'] . "' and `time`.`date` = '" . $rec['date'] . "';"; //echo $sql; //die(); } } else { $timeIn = $time; $timeOut = ""; $sql = "INSERT INTO `time`.`time` (`id`, `staffId`, `date`, `timeIn`,`timeOut`, `machine`) VALUES (NULL, '{$staffid}', '{$date}', '{$timeIn}','{$timeOut}', '{$finger}');"; } //end query check date //$sql = "INSERT INTO `time`.`time` (`id`, `staffId`, `date`, `time`, `machine`,`timestamp`) VALUES (NULL, '$staffid', '$date', '$time', '$finger','$timestamp');"; //insert to table mysql_query($sql); $i++; } //end while } else { die("cannot open the file."); // error opening the file. } echo $tmp_file; fclose($handle1); echo "</table>"; //end read file to make sql } } closedir($handle); } //====end read dir }
@teknik.io</a></li> <?php if ($Profile_User->blog_title) { ?> <li class="list-group-item text-right"><span class="pull-left"><strong>Blog</strong></span> <a href="<?php echo get_page_url('blog', $CONF) . '/' . $Profile_User->username; ?> " id="blog_title"><?php echo $Profile_User->blog_title; ?> </a></li> <?php } ?> <?php if (is_dir("G:\\Repositories\\u\\" . $Profile_User->username) && !is_dir_empty("G:\\Repositories\\u\\" . $Profile_User->username)) { ?> <li class="list-group-item text-right"><span class="pull-left"><strong>Git</strong></span> <a href="<?php echo get_page_url('git', $CONF) . '/u/' . $Profile_User->username; ?> ">Public Repos</a></li> <?php } ?> <?php if ($own_profile) { ?> <li class="list-group-item text-center"><button type="button" class="btn btn-danger" id="delete_account">Delete Account</button></li> <?php } ?>
/** * Recurrsively removes everything in the given path, i.e. all files and subdirectories within the * given directory. * @param string $path * @return boolean True if the directory was successfully deleted, otherwise false. In case of an error, see the logs. */ function rmdirs($path) { // Make sure the file even is a file. :I if (!is_dir($path)) { logMsg('rmdirs: attempted to recurrsively remove directories in path ' . $path . ', but its not a directory!', 5, 5); return false; } // Make directory separators platform-specifically uniform. $files = glob("{$path}/*"); foreach ($files as $file) { if (is_dir($file)) { rmdirs($file); } else { unlink($file); } } if (!is_dir_empty($path)) { logMsg('rmdirs: failed to delete everything in the directory', 5, 5); return false; } return rmdir($path); }
* delete thumbnail file */ if (file_exists($thumb)) { if (!unlink($thumb)) { $error = error_get_last(); write_log("Error: " . $error["message"], __FILE__, __LINE__); $redir_url = "/Gallery?spgmGal=" . urlencode($system) . "&removed=1"; } } else { write_log("Error: Could not remove " . $thumb . " - file doesn't exist", __FILE__, __LINE__); $redir_url = "/Gallery?spgmGal=" . urlencode($system) . "&removed=1"; } /** * delete directory if it's now empty */ if (is_dir_empty($path . "/thumbs")) { $redir_url = "/Gallery?removed"; // remove thumbs dir first if (!rmdir($path . "/thumbs")) { $error = error_get_last(); write_log("Error: " . $error["message"], __FILE__, __LINE__); $redir_url = "/Gallery?removed=1"; } // remove dir if (!rmdir($path)) { $error = error_get_last(); write_log("Error: " . $error["message"], __FILE__, __LINE__); $redir_url = "/Gallery?removed=1"; } } echo $redir_url;
/** * Recursively checks if the directories within the given path are empty and removes them if so. * @param string $path to clean * @return boolean True if the entire path was successfully cleaned of empty directories, otherwise false. */ protected static function cleanpath($path) { if (is_dir_empty($path)) { if (@rmdir($path)) { return self::cleanpath(dirname($path)); } else { logMsg("InstallationManager: failed to remove directory {$path}", 4, false); return false; } } return true; }
</form> </div> <?php } ?> <table class="table table-striped table-advance table-hover"> <tbody> <tr> <th></th> <th>Filename</th> <th>Size</th> <th>Action</th> </tr><?php if (is_dir_empty("files/")) { write2logfile("No files found", "index.php"); ?> </table> <center><h3>You don't have any files!</h3></center> <?php } if ($handle = opendir("files/")) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != ".." && $entry != ".DS_Store" && $entry != ".htaccess" && $entry != ".htdocs") { $sum += filesize("files/" . $entry); $num = $num + 1; $filesize = filesize("files/" . $entry); $filesize = $filesize / 1024; $filesize = $filesize / 1024; $filesize = round($filesize, 3);