コード例 #1
0
ファイル: 5.php プロジェクト: ABabiy/homeworks
<?php

/**
 * Created by PhpStorm.
 * User: AlexN
 * Date: 07.02.2016
 * Time: 4:03
 */
/*
 5. Написать функцию, которая выводит список файлов в заданной директории, которые
содержат искомое слово.  Директория и искомое слово задаются как параметры функции.
*/
function filesInDir($dir, $fileName)
{
    if (is_dir($dir)) {
        if ($handle = opendir($dir)) {
            while (false !== ($file = readdir($handle))) {
                if ($file != "." && $file != ".." && !is_dir($file) && strstr($file, $fileName) == true) {
                    echo "{$file} <br> ";
                }
            }
            closedir($handle);
        }
    } else {
        die("Вы не задали параметр функции ДИРЕКТОРИЯ!");
    }
}
filesInDir('c:/', "fi");
コード例 #2
0
function filesInDir($path, &$files = array())
{
    $dir = opendir($path . "/.");
    while ($item = readdir($dir)) {
        if (is_file($sub = $path . "/" . $item)) {
            $files[] = $item;
        } else {
            if ($item != "." and $item != "..") {
                filesInDir($sub, $files);
            }
        }
    }
    return $files;
}
コード例 #3
0
ファイル: 4.php プロジェクト: ABabiy/homeworks
<?php

/**
 * Created by PhpStorm.
 * User: AlexN
 * Date: 07.02.2016
 * Time: 3:26
 */
/*
 4. Написать функцию, которая выводит список файлов в заданной директории.
Директория задается как параметр функции.
*/
function filesInDir($dir)
{
    if (is_dir($dir)) {
        if ($handle = opendir($dir)) {
            while (false !== ($file = readdir($handle))) {
                if ($file != "." && $file != ".." && !is_dir($file)) {
                    echo "{$file} <br> ";
                }
            }
            closedir($handle);
        }
    } else {
        die("Вы не задали параметр функции ДИРЕКТОРИЯ!");
    }
}
filesInDir('c:/');
コード例 #4
0
 function _resizePhoto()
 {
     //comment_thumb 40x40
     //post_thumb 50x50
     //profile_thumb 60x60
     //thumb/photos 60x60
     $arrayMIME = array('.jpg', '.png', '.jpeg');
     $dirPath = "./image/comment_thumb/";
     $i = 0;
     foreach (filesInDir($dirPath) as $file) {
         $ext_name_array = explode_name($file);
         if (in_array($ext_name_array['ext'], $arrayMIME)) {
             //chmod($dirPath.$file,777);
             $size = getimagesize($dirPath . $file);
             if ($size[0] > 40 or $size[1] > 40) {
                 makeThumb($file, $dirPath, 40, 40);
                 $i++;
             }
         }
     }
     echo "resize comment_thumb:{$i} items<br/>";
     $dirPath = "./image/post_thumb/";
     $i = 0;
     foreach (filesInDir($dirPath) as $file) {
         $ext_name_array = explode_name($file);
         if (in_array($ext_name_array['ext'], $arrayMIME)) {
             //chmod($dirPath.$file,777);
             $size = getimagesize($dirPath . $file);
             if ($size[0] > 50 or $size[1] > 50) {
                 makeThumb($file, $dirPath, 50, 50);
                 $i++;
             }
         }
     }
     echo "resize post_thumb:{$i} items<br/>";
     $dirPath = "./image/profile_thumb/";
     $i = 0;
     foreach (filesInDir($dirPath) as $file) {
         $ext_name_array = explode_name($file);
         if (in_array($ext_name_array['ext'], $arrayMIME)) {
             //chmod($dirPath.$file,777);
             $size = getimagesize($dirPath . $file);
             if ($size[0] > 60 or $size[1] > 60) {
                 makeThumb($file, $dirPath, 60, 60);
                 $i++;
             }
         }
     }
     echo "resize profile_thumb:{$i} items<br/>";
     $dirPath = "./image/thumb/photos/";
     $i = 0;
     foreach (filesInDir($dirPath) as $file) {
         $ext_name_array = explode_name($file);
         if (in_array($ext_name_array['ext'], $arrayMIME)) {
             //chmod($dirPath.$file,777);
             $size = getimagesize($dirPath . $file);
             if ($size[0] > 60 or $size[1] > 60) {
                 makeThumb($file, $dirPath, 60, 60);
                 $i++;
             }
         }
     }
     echo "resize thumb/photos:{$i} items<br/>";
 }