简体   繁体   English

从Scandir()将数组插入PHP日历脚本

[英]Inserting Array from Scandir() into PHP Calendar Script

Background : Looking to put local marine radio cruisers net online. 背景 :希望将本地海上无线电巡洋舰网络置于网上。 Net being received via SDR piped to sox for encoding as mp3 file. 通过SDR接收到的净网络通过管道传输到sox,以编码为mp3文件。 File uploaded to server in dedicated directory (/data), naming convention (YY)(MM)(DD).mp3 At this time the project is in test mode, and files are not always recorded or uploaded daily 将文件上载到服务器的专用目录(/ data)中,命名约定(YY)(MM)(DD).mp3目前项目处于测试模式,并且文件并非每天都记录或上传

Goal : Server side (PHP) calendar script which will parse the /data directory for an array and recolor the calendar cells background for dates matching the files naming convention. 目标 :服务器端(PHP)日历脚本,它将解析/ data目录中的数组,并为日历单元格背景重新着色以查找与文件命名约定匹配的日期。 Clicking on a highlighted cell will open the associated file. 单击突出显示的单元格将打开关联的文件。

Status : Have very simple (but adequate?) calendar script with no exterior libraries or css (code follows). 状态 :具有非常简单(但足够吗?)的日历脚本,没有外部库或css(代码如下)。 Php experience limited and rusty. PHP经验有限且生锈。 Unsure how and where to integrate scandir() function and other required bits to achieve goal. 不确定如何以及在何处集成scandir()函数和其他所需位以实现目标。 Assistance appreciated. 协助表示赞赏。

<html>
<head>
  <title>Boot Key Calendar Test</title>
</head>
<body>

<?php
    $monthNames = Array(
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December"
    );

    if (!isset($_REQUEST["month"]))
        $_REQUEST["month"] = date("n");
    if (!isset($_REQUEST["year"]))
        $_REQUEST["year"] = date("Y");

    $cMonth = $_REQUEST["month"];
    $cYear  = $_REQUEST["year"];

    $prev_year  = $cYear;
    $next_year  = $cYear;
    $prev_month = $cMonth - 1;
    $next_month = $cMonth + 1;

    if ($prev_month == 0)
      {
        $prev_month = 12;
        $prev_year  = $cYear - 1;
      }
    if ($next_month == 13)
      {
        $next_month = 1;
        $next_year  = $cYear + 1;
      }
?>
<br><br>
<table width="400" border="2" align="center">
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" align="left">  <a href="<?php
    echo $_SERVER["PHP_SELF"] . "?month=" . $prev_month . "&year=" .        $prev_year;
?>" style="color:#FFFFFF">Previous</a></td>
<td width="50%" align="right"><a href="<?php
        echo $_SERVER["PHP_SELF"] . "?month=" . $next_month . "&year=" .     $next_year;
?>" style="color:#FFFFFF">Next</a>  </td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%"  border="0" cellpadding="2" cellspacing="2">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php
    echo $monthNames[$cMonth - 1] . ' ' . $cYear;
?></strong></td>
</tr>
<tr>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">  <strong>S</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"> <strong>M</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong>    </td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong>    </td>
</tr>

<?php
    $timestamp = mktime(0, 0, 0, $cMonth, 1, $cYear);
    $maxday    = date("t", $timestamp);
    $thismonth = getdate($timestamp);
    $startday  = $thismonth['wday'];
    for ($i = 0; $i < ($maxday + $startday); $i++)
      {
        if (($i % 7) == 0)
            echo "<tr>";
        if ($i < $startday)
            echo "<td></td>";
        else
            echo "<td align='center' valign='middle' height='40px'>" .     ($i - $startday + 1) . "</td>";
        if (($i % 7) == 6)
            echo "</tr>";
      }
?>

</table>
</td>
</tr>
</table>

<br><br>


</body>
</html>

Working example at http://bootkeycruisers.net/calendar.php http://bootkeycruisers.net/calendar.php上的工作示例

This works: 这有效:

    <?php
    $monthNames = Array(
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December"
    );
    if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
    if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
    $cMonth = $_REQUEST["month"];
    $cYear = $_REQUEST["year"];
    $prev_year = $cYear;
    $next_year = $cYear;
    $prev_month = $cMonth - 1;
    $next_month = $cMonth + 1;
    if ($prev_month == 0)
      {
        $prev_month = 12;
        $prev_year = $cYear - 1;
      }
    if ($next_month == 13)
      {
        $next_month = 1;
        $next_year = $cYear + 1;
      }
    ?>
    <br /><br />
    <table width="400" border="2" align="center">
    <tr align="center">
    <td bgcolor="#999999" style="color:#FFFFFF">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="50%" align="left">  <a href="<?php
    echo $_SERVER["PHP_SELF"] . "?month=" . $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td>
    <td width="50%" align="right"><a href="<?php
    echo $_SERVER["PHP_SELF"] . "?month=" . $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a>  </td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td align="center">
    <table width="100%"  border="0" cellpadding="2" cellspacing="2">
    <tr align="center">
    <td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php
    echo $monthNames[$cMonth - 1] . ' ' . $cYear; ?></strong></td>
    </tr>
    <tr>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
    </tr>
    <?php
    $timestamp = mktime(0, 0, 0, $cMonth, 1, $cYear);
    $maxday = date("t", $timestamp);
    $thismonth = getdate($timestamp);
    $startday = $thismonth['wday'];
    for ($i = 0; $i < ($maxday + $startday); $i++)
      {
        if (($i % 7) == 0) echo "<tr>";
        if ($i < $startday) echo "<td></td>";
        else
          {
        $class = 'inactive';
        $display = ($i - $startday + 1);
        $month = str_pad($cMonth, 2, 0, STR_PAD_LEFT);
        $day = str_pad(($i - $startday + 1) , 2, 0, STR_PAD_LEFT);
        $date = $cYear . $month . $day;
        if (is_file("data/$date.mp3"))
          {
            $class = 'active';
            $display = "<a href='?d=$date'>" . ($i - $startday + 1) . "</a>";
          }
        echo "<td align='center' valign='middle' height='40px' class='$class'>$display</td>";
          }
      }
    ?>
    </table>
    </td>
    </tr>
    </table>
    <br><br>
    <?php
    if (isset($_GET['d']))
      {
        if (is_file("data/{$_GET['d']}.mp3"))
          {
    ?>
    <center>
    <audio controls autoplay>
    <source src="data/<?php
        echo htmlentities($_GET['d']); ?>.mp3" type="audio/mpeg">
        Your browser does not support the audio element.
    </audio>
    </center
    <?php
          }
      }

    ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM