LoginSignup
1
0

More than 1 year has passed since last update.

常時ディレクトリ監視を行い任意の画像ファイルだけ別のディレクトリへ移動するコードです。

Last updated at Posted at 2022-11-02

コードを書いた経緯

  • while(true)の使い道を一つの例として記載しました。

常時監視するLinuxコマンド
nohup php File_Check.php &
ディレクトリ構成
├── File_Check.php
├── upload
└── data
File_Check.php
<?php
if($argv[0]){
    while(true){
        if($result = is_scandir("./upload")){
            foreach($result as $key=>$value){
                rename("./upload/$value","./data/$value");
            }
        }
        sleep(3);    
    }
}

function is_scandir(string $dirname="",array $ext_list = ["png","jpg"]){
    $is_filelest = [];
    $result = scandir($dirname);
    foreach($result as $key=>$value){
        $ext = substr($value, strrpos($value, '.') + 1);
        if(in_array($ext,$ext_list,false)!== false){
            $is_filelest[] = $value;
        }
    }
    return count($is_filelest)>0 ? $is_filelest : false;
}
1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0