dsag14654 2012-06-02 21:04
浏览 11
已采纳

如何以快速方式从多个目录中运行相同的php文件?

In my books folder , there are nearly 200 book folder like :

--books (folder)  
  |--book1(folder)
  |--book2(folder)
  |--(this continues until 200)  

What I want is that I need to create some directories inside 200 folder by fetching data from mysql about folder. I can make it manually but making one by one is very inefficient.

I coded create_folder.php and insert it book1 folder to see how it give a result :

$current_folder = basename(dirname(__FILE__));

// I choose which directories are inserted.
$sql = "SELECT directory FROM ..............WHERE folder = {$current_folder} ";

$result = mysql_query($sql);

while ($row = mysql_fetch_array($result)) {
  mkdir($row['directory']);
}  

So, in my book1 folder, I created directories via database.
After that, I created glob.php file in order to insert create_folder.php in all 200 directories automaticly.(I put glob.php in main books folder. Here :

$content = file_get_contents("create_folder.php");

$files = glob( './*' );
foreach( $files as $file ) {
if( is_dir( $file ) && is_writable( $file ) ) {
    file_put_contents( $file . '/create_folder.php', $content );
    }
}

Now, inside 200 folders, there is create_folder.php. The problem is, I must make create_folder.php run in all 200 directories in order to create sub directories. Any quick way to run it? Thanks...

  • 写回答

1条回答 默认 最新

  • dttphb59319 2012-06-02 21:24
    关注
    $files = glob( './*' );
    foreach( $files as $file ) {
    if( is_dir( $file ) && is_writable( $file ) ) {
    $output = exec('php -l '.$file.'/create_folder.php',$function_output,$return);
    print $output."
    ";
    print $return."
    ";
    var_dump($function_output);
        }
    }
    

    Run this in your root directory. SO if your sites are in /home/user/site1, /home/user/site2, then run it from /home/user.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大