簡體   English   中英

從Scandir()將數組插入PHP日歷腳本

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

背景 :希望將本地海上無線電巡洋艦網絡置於網上。 通過SDR接收到的凈網絡通過管道傳輸到sox,以編碼為mp3文件。 將文件上載到服務器的專用目錄(/ data)中,命名約定(YY)(MM)(DD).mp3目前項目處於測試模式,並且文件並非每天都記錄或上傳

目標 :服務器端(PHP)日歷腳本,它將解析/ data目錄中的數組,並為日歷單元格背景重新着色以查找與文件命名約定匹配的日期。 單擊突出顯示的單元格將打開關聯的文件。

狀態 :具有非常簡單(但足夠嗎?)的日歷腳本,沒有外部庫或css(代碼如下)。 PHP經驗有限且生銹。 不確定如何以及在何處集成scandir()函數和其他所需位以實現目標。 協助表示贊賞。

<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>

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

這有效:

    <?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