当前位置: 首页>>代码示例>>PHP>>正文


PHP RecursiveIteratorIterator::getRealPath方法代码示例

本文整理汇总了PHP中RecursiveIteratorIterator::getRealPath方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveIteratorIterator::getRealPath方法的具体用法?PHP RecursiveIteratorIterator::getRealPath怎么用?PHP RecursiveIteratorIterator::getRealPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RecursiveIteratorIterator的用法示例。


在下文中一共展示了RecursiveIteratorIterator::getRealPath方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * Do the job.
  * Throw exceptions on errors (the job will be retried).
  */
 public function execute()
 {
     global $CFG;
     $tmpdir = $CFG->tempdir;
     // Default to last weeks time.
     $time = time() - $CFG->tempdatafoldercleanup * 3600;
     $dir = new \RecursiveDirectoryIterator($tmpdir);
     // Show all child nodes prior to their parent.
     $iter = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::CHILD_FIRST);
     // An array of the full path (key) and date last modified.
     $modifieddateobject = array();
     // Get the time modified for each directory node. Nodes will be updated
     // once a file is deleted, so we need a list of the original values.
     for ($iter->rewind(); $iter->valid(); $iter->next()) {
         $node = $iter->getRealPath();
         if (!is_readable($node)) {
             continue;
         }
         $modifieddateobject[$node] = $iter->getMTime();
     }
     // Now loop through again and remove old files and directories.
     for ($iter->rewind(); $iter->valid(); $iter->next()) {
         $node = $iter->getRealPath();
         if (!is_readable($node)) {
             continue;
         }
         // Check if file or directory is older than the given time.
         if ($modifieddateobject[$node] < $time) {
             if ($iter->isDir() && !$iter->isDot()) {
                 // Don't attempt to delete the directory if it isn't empty.
                 if (!glob($node . DIRECTORY_SEPARATOR . '*')) {
                     if (@rmdir($node) === false) {
                         mtrace("Failed removing directory '{$node}'.");
                     }
                 }
             }
             if ($iter->isFile()) {
                 if (@unlink($node) === false) {
                     mtrace("Failed removing file '{$node}'.");
                 }
             }
         } else {
             // Return the time modified to the original date only for real files.
             if ($iter->isDir() && !$iter->isDot()) {
                 touch($node, $modifieddateobject[$node]);
             }
         }
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:53,代码来源:file_temp_cleanup_task.php

示例2: execute

 /**
  * Do the job.
  * Throw exceptions on errors (the job will be retried).
  */
 public function execute()
 {
     global $CFG;
     $tmpdir = $CFG->tempdir;
     // Default to last weeks time.
     $time = strtotime('-1 week');
     $dir = new \RecursiveDirectoryIterator($tmpdir);
     // Show all child nodes prior to their parent.
     $iter = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::CHILD_FIRST);
     for ($iter->rewind(); $iter->valid(); $iter->next()) {
         $node = $iter->getRealPath();
         if (!is_readable($node)) {
             continue;
         }
         // Check if file or directory is older than the given time.
         if ($iter->getMTime() < $time) {
             if ($iter->isDir() && !$iter->isDot()) {
                 // Don't attempt to delete the directory if it isn't empty.
                 if (!glob($node . DIRECTORY_SEPARATOR . '*')) {
                     if (@rmdir($node) === false) {
                         mtrace("Failed removing directory '{$node}'.");
                     }
                 }
             }
             if ($iter->isFile()) {
                 if (@unlink($node) === false) {
                     mtrace("Failed removing file '{$node}'.");
                 }
             }
         }
     }
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:36,代码来源:file_temp_cleanup_task.php

示例3: execute

 /**
  * Executes the transformation process.
  *
  * @throws Zend_Console_Getopt_Exception
  *
  * @return void
  */
 public function execute()
 {
     $results = array();
     $longest_name = 0;
     /** @var RecursiveDirectoryIterator $files */
     $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/../'));
     while ($files->valid()) {
         // skip abstract files
         if (!$files->isFile() || $files->getBasename() == 'Abstract.php') {
             $files->next();
             continue;
         }
         // convert the filename to a class
         $class_name = 'DocBlox_Task_' . str_replace(DIRECTORY_SEPARATOR, '_', $files->getSubPath()) . '_' . $files->getBasename('.php');
         // check if the class exists, if so: add it to the list
         if (class_exists($class_name)) {
             $name = $files->getBasename('.php');
             $longest_name = max(strlen($name), $longest_name);
             $results[strtolower($files->getSubPath())][strtolower($name)] = $files->getRealPath();
         }
         $files->next();
     }
     // echo the list of namespaces with their tasks
     ksort($results, SORT_STRING);
     foreach ($results as $namespace => $tasks) {
         echo $namespace . PHP_EOL;
         asort($tasks, SORT_STRING);
         foreach ($tasks as $task => $filename) {
             // get the short description by reflecting the file.
             $refl = new DocBlox_Reflection_File($filename, false);
             $refl->setLogLevel(DocBlox_Core_Log::QUIET);
             $refl->process();
             /** @var DocBlox_Reflection_Class $class */
             $class = current($refl->getClasses());
             echo ' :' . str_pad($task, $longest_name + 2) . $class->getDocBlock()->getShortDescription() . PHP_EOL;
         }
     }
     echo PHP_EOL;
 }
开发者ID:rvanvelzen,项目名称:phpDocumentor2,代码行数:46,代码来源:List.php

示例4: cron_delete_from_temp

/**
 * Delete files and directories older than one week from directory provided by $CFG->tempdir.
 *
 * @exception Exception Failed reading/accessing file or directory
 * @return bool True on successful file and directory deletion; otherwise, false on failure
 */
function cron_delete_from_temp()
{
    global $CFG;
    $tmpdir = $CFG->tempdir;
    // Default to last weeks time.
    $time = strtotime('-1 week');
    try {
        $dir = new RecursiveDirectoryIterator($tmpdir);
        // Show all child nodes prior to their parent.
        $iter = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST);
        for ($iter->rewind(); $iter->valid(); $iter->next()) {
            $node = $iter->getRealPath();
            if (!is_readable($node)) {
                continue;
            }
            // Check if file or directory is older than the given time.
            if ($iter->getMTime() < $time) {
                if ($iter->isDir() && !$iter->isDot()) {
                    if (@rmdir($node) === false) {
                        mtrace("Failed removing directory '{$node}'.");
                    }
                }
                if ($iter->isFile()) {
                    if (@unlink($node) === false) {
                        mtrace("Failed removing file '{$node}'.");
                    }
                }
            }
        }
    } catch (Exception $e) {
        mtrace('Failed reading/accessing file or directory.');
        return false;
    }
    return true;
}
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:41,代码来源:cronlib.php

示例5: test_file_temp_cleanup_task

    /**
     * Test that the file_temp_cleanup_task removes directories and
     * files as expected.
     */
    public function test_file_temp_cleanup_task() {
        global $CFG;

        // Create directories.
        $dir = $CFG->tempdir . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . 'backup01' . DIRECTORY_SEPARATOR . 'courses';
        mkdir($dir, 0777, true);

        // Create files to be checked and then deleted.
        $file01 = $dir . DIRECTORY_SEPARATOR . 'sections.xml';
        file_put_contents($file01, 'test data 001');
        $file02 = $dir . DIRECTORY_SEPARATOR . 'modules.xml';
        file_put_contents($file02, 'test data 002');
        // Change the time modified for the first file, to a time that will be deleted by the task (greater than seven days).
        touch($file01, time() - (8 * 24 * 3600));

        $task = \core\task\manager::get_scheduled_task('\\core\\task\\file_temp_cleanup_task');
        $this->assertInstanceOf('\core\task\file_temp_cleanup_task', $task);
        $task->execute();

        // Scan the directory. Only modules.xml should be left.
        $filesarray = scandir($dir);
        $this->assertEquals('modules.xml', $filesarray[2]);
        $this->assertEquals(3, count($filesarray));

        // Change the time modified on modules.xml.
        touch($file02, time() - (8 * 24 * 3600));
        // Change the time modified on the courses directory.
        touch($CFG->tempdir . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . 'backup01' . DIRECTORY_SEPARATOR .
                'courses', time() - (8 * 24 * 3600));
        // Run the scheduled task to remove the file and directory.
        $task->execute();
        $filesarray = scandir($CFG->tempdir . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . 'backup01');
        // There should only be two items in the array, '.' and '..'.
        $this->assertEquals(2, count($filesarray));

        // Change the time modified on all of the files and directories.
        $dir = new \RecursiveDirectoryIterator($CFG->tempdir);
        // Show all child nodes prior to their parent.
        $iter = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::CHILD_FIRST);

        for ($iter->rewind(); $iter->valid(); $iter->next()) {
            $node = $iter->getRealPath();
            touch($node, time() - (8 * 24 * 3600));
        }

        // Run the scheduled task again to remove all of the files and directories.
        $task->execute();
        $filesarray = scandir($CFG->tempdir);
        // All of the files and directories should be deleted.
        // There should only be two items in the array, '.' and '..'.
        $this->assertEquals(2, count($filesarray));
    }
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:56,代码来源:scheduled_task_test.php

示例6: test_cron_delete_from_temp

 /**
  * Test removing files and directories from tempdir.
  *
  * @dataProvider cron_delete_from_temp_provider
  * @param array $nodes List of files and directories
  * @param array $expected The expected results
  */
 public function test_cron_delete_from_temp($nodes, $expected)
 {
     global $CFG;
     $tmpdir = $CFG->tempdir;
     foreach ($nodes as $data) {
         if ($data->isdir) {
             mkdir($tmpdir . $data->path, $CFG->directorypermissions, true);
         }
     }
     // We need to iterate through again since adding a file to a directory will
     // update the modified time of the directory.
     foreach ($nodes as $data) {
         touch($tmpdir . $data->path, time() + $data->time);
     }
     cron_delete_from_temp();
     $dir = new RecursiveDirectoryIterator($tmpdir);
     $iter = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST);
     $actual = array();
     for ($iter->rewind(); $iter->valid(); $iter->next()) {
         if (!$iter->isDot()) {
             $actual[] = $iter->getRealPath();
         }
     }
     // Sort results to guarantee actual order.
     sort($actual);
     $this->assertEquals($expected, $actual);
 }
开发者ID:miguelangelUvirtual,项目名称:uEducon,代码行数:34,代码来源:cronlib_test.php

示例7: build_files

 public function build_files()
 {
     $id = 0;
     $partial_stop = 0;
     $maxSize = 0;
     $indexStep = 0;
     $maxInserts = 0;
     $files = array();
     if (isset($_POST['partialStop'])) {
         $partial_stop = (int) $_POST['partialStop'];
     }
     //Max Filesize check
     if (isset($_POST['maxSize'])) {
         $maxSize = (int) $_POST['maxSize'];
     }
     if (!$maxSize) {
         $maxSize = 5242880;
         //Default value.
     }
     //IndexStep check
     if (isset($_POST['indexStep'])) {
         $indexStep = (int) $_POST['indexStep'];
     }
     if (!$indexStep) {
         $indexStep = 3000;
     }
     //MaxInserts check
     if (isset($_POST['maxInserts'])) {
         $maxInserts = (int) $_POST['maxInserts'];
     }
     if (!$maxInserts) {
         $maxInserts = 300;
     }
     chdir(JPATH_ROOT);
     //If we don't have a partial stop count, then this is a new request.
     //We should therefore clear the database.
     if (!$partial_stop) {
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $db->setQuery("DELETE FROM " . $db->quoteName('#__jhackguard_scan_files'));
         $db->query();
     }
     $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('./'));
     /* And off we go into the loop */
     $sql_delimiter = 0;
     $total_count = 0;
     $stopped = 0;
     while ($it->valid()) {
         //We do no need ., .., or directories. Only files.
         if (!$it->isDot() and !$it->isDir()) {
             if ($it->getSize() > 0 and $it->getSize() < $maxSize) {
                 //We also do not need empty files or files bigger than 5MB.
                 $total_count++;
                 if ($partial_stop > 0 and $partial_stop > $total_count) {
                     $it->next();
                     continue;
                     //We don't want these items. We indexed them the last run.
                 }
                 $files[] = $it->getRealPath();
                 $sql_delimiter++;
                 if ($sql_delimiter > $maxInserts) {
                     //Perform insert.
                     $db = JFactory::getDbo();
                     $query = $db->getQuery(true);
                     $query->insert($db->quoteName('#__jhackguard_scan_files'));
                     $query->columns('fname');
                     foreach ($files as $path) {
                         $query->values($db->quote($path));
                     }
                     $db->setQuery($query);
                     $db->query();
                     //Reset sql_delimiter
                     $sql_delimiter = 0;
                     //Reset files array
                     $files = array();
                 }
                 if ($total_count == $partial_stop + $indexStep) {
                     $stopped = 1;
                     break;
                     //We have reached the 3k limit per run.
                 }
             }
         }
         $it->next();
     }
     //Did we miss to import the last batch of the files?
     if (count($files) > 0) {
         //Yup..
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->insert($db->quoteName('#__jhackguard_scan_files'));
         $query->columns('fname');
         foreach ($files as $path) {
             $query->values($db->quote($path));
         }
         $db->setQuery($query);
         $db->query();
         $files = array();
     }
     if ($stopped) {
//.........这里部分代码省略.........
开发者ID:ejailesb,项目名称:repo_empr,代码行数:101,代码来源:ondemandscans.raw.php

示例8: array

$infected = array();
$scanned = 0;
$hits = 0;
/* And off we go into the loop */
while ($it->valid()) {
    try {
        if (!$it->isDot() and !$it->isDir()) {
            // First check the MD5 sum of the file.
            // Matched files will not be opened for reading to save time.
            // Only scan files bigger than 0 bytes and less than 2MB
            $fmd5 = md5_file($it->key());
            // Check if AppFocus has been defined and process the file first.
            if ($config->app_focused_run) {
                if (!$config->afo->hash_match($it->key(), $fmd5)) {
                    $hits++;
                    $infected[$it->getRealPath()] = array('explain' => '[modified_core_file]', 'score' => 100);
                    $it->next();
                    continue;
                }
            }
            if ($it->getSize() > 0 and $it->getSize() < 2048576) {
                if (in_array($fmd5, $false_positives)) {
                    $it->next();
                    continue;
                }
                if (in_array($fmd5, $md5s)) {
                    //md5 hit
                    $hits++;
                    $infected[$it->getRealPath()] = array('explain' => '[md5sum_match]', 'score' => 100);
                } else {
                    $s = new FileScanner();
开发者ID:pfire,项目名称:HackSearch,代码行数:31,代码来源:hacksearch.php


注:本文中的RecursiveIteratorIterator::getRealPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。