doujing1156 2015-03-03 12:32
浏览 19

需要帮助使用方法或案例声明更新PHP脚本

This script checks the modified date on a Postfix mailbox folder.

The issue is, I have more than one location that needs to be check.

Folder /mnt/mail1/ contains mail dirs a,b,d,g

Folder /mnt/mail2/ contains the rest c,e,f,h,........,x,z

The script is run simply via the URL https://URL/index.php?email=charlie@delta.com

I need the script to check in the correct mount point depending on the email address being checked. In the case above it should check in /mnt/mail2/d/e/delta.com/.....

Please help. I know 0 to nothing about php.

<?php

if (isset($_REQUEST["email"])) {
    $emailaddress= trim($_REQUEST["email"]);
    $emailparts = explode("@",$emailaddress);
    if (sizeof($emailparts) != 2) {
            print "invalid-email,,,,";
            exit();
    }
    $username = $emailparts[0];
    $domain = $emailparts[1];      
    $basedir = "/mnt/mail1/";
    $livePrefix = $basedir;
    $archivePrefix = $basedir."archive/";
    $livePath = $livePrefix . substr($domain,0,1) . "/" . substr($domain,1,1) . "/" . $domain . "/" . substr($username,0,1) . "/" .  $username;
    $archivePath = $archivePrefix . $domain ;
    $liveStat = stat( $livePath . "/" . "cur");
    $archStat = false;
    if ( file_exists( $archivePath ) && is_dir( $archivePrefix ) ) {
            $arhiveDirs = scandir($archivePath);
            foreach( $arhiveDirs  as $i => $fname ) {
                    if ( stripos( $fname , $username . "-"  ) !== false ) {
                            $archivePath = $archivePath . "/" . $fname ;
                            $archStat = stat( $archivePath . "/cur" );
                            break;
                    }
            }
    }
    $status="lost" ;
    if ( $liveStat != false ) {
            $status = "live" . "," .  date("Y-m-d H:i:s", $liveStat['mtime'] ) . "," . sizeof( scandir($livePath . "/new") ) . "," ;
    } else if ($archStat != false ) {
            $status = "archived,,,";
    } else {
            $status = "lost,,,";
    }

    if ($archStat != false ) {
            $status = $status .  date("Y-m-d H:i:s", $archStat['mtime'] ) . "," . sizeof( scandir($archivePath . "/new") )  ;
    } else {
            $status = $status .  "," ;
    }

    print $status ;
    exit();
} else {
    print "error,,,,";
    exit();
}


?>
  • 写回答

2条回答 默认 最新

  • dpdfh60088 2015-03-03 12:44
    关注

    Without reading the code and knowing much about php: First, you need to get the email address from the link. Use regex for this. Second, explode the email and get the domain (also with regex).

    $domain =

    Get the first and the second character of the domain: $domain[0] and $domain[1].

    Then you should choose between the two folders two check. Do it with a switch, with 4 main cases: a, b, d, g and a default case that checks the others.

    ... by the way: shouldn't the case above check the /mnt/mail1/ folder?

    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助