基礎から解る!PHP入門講座 プログラム入門に最適な言語、PHPを学ぼう

基礎から解る!PHP入門講座

プログラム入門に最適な言語、PHPを学ぼう      

    ファイル 13−3

    <?php
    error_reporting(1);
    /*------------------------------------------パスワード”の設定------*/
    $pass_w = $_POST['password_w'];
      if($pass_w==null){
        $pass_w=$_COOKIE['password_m'];
      }
    setcookie("password_m", $pass_w, time()+60*60);

    $login = $_POST['loginn'];        /*ログオフの設定*/          
      if($login == "LOGOFF") {
        setcookie("password_m");      /*クッキー"password"をクリア*/
        $pass_w = "";            /*パスワードデータをクリア*/
      }
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html lang="ja"><head>
    <meta http-equiv="Content-type" content="text/html; charset=EUC-JP">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <link rel="stylesheet" href="../style.css">
    <title>写真日記</title>
    <style type="text/css">
    .mess {
    text-align:left;
    width:610px;
    padding :5px 5px 3px 5px;
    margin:0px 0px 5px 0px;
    border-style:solid;
    border-width:1px;
    background-color:#cdfaff;
    border-color:#abcdef;}

    .err {
    text-align:left;
    width:610px;
    padding :5px 5px 3px 5px;
    margin:0px 0px 5px 0px;
    border-style:solid;
    border-width:1px;
    background-color:#cdfaff;
    border-color:#abcdef;}

    .waku {
    text-align:left;
    width:100%;
    padding :5px 5px 3px 10px;
    margin:0px 0px 5px 0px;
    border-style:none;
    border-width:0px;
    background-color:#ffff;
    border-color:#abcdef;}

    .top {
    font-size:15px;
    text-align:left;
    width:100%;
    padding :5px 5px 3px 5px;
    margin:0px 0px 5px 0px;
    border-style:solid;
    border-width:1px;
    background-color:#cdfaff;
    border-color:#abcdef;
    font-weight:bold
    }

    .next {
    font-size:12px;
    text-align:left;
    width:100%;
    padding :5px 5px 3px 5px;
    margin:0px 0px 5px 0px;
    border-style:solid;
    border-width:1px;
    background-color:#cdfffa;
    border-color:#abcdef;
    }
    </style>
    </head>
    <body><div class="file2"><h2>写真日記</h2>
    <?php
    if($pass_w != "pass"){
      echo "<form action='".$_SERVER["PHP_SELF"]."' method='post'>¥n";
      echo "<input type='password' name='password_w' size='12'>¥n";
      echo " <input type='submit' name ='loginn' value='LOGIN'>¥n";
      echo "</form>";
      echo "パスワードを入力してください。pass です。";
    } else if($pass_w == "pass"){
    /*------------------------------------------LOGOFFの設定------*/
      echo "<form action='".$PHP_SELF."' method='post'>";
      echo "<table width='610' border='0'><tr><td valign='middle'>";
      echo "<span style='margin:0px;font-size:15px'>";
      echo date("Y/m/d") . "</span></td>¥n";
      echo "<td align='right'><input type='submit' name ='loginn' value='LOGOFF'>";
      echo "</td></tr></table></form>";
    /*------------------------------------------------*/
      echo "<form action='".$PHP_SELF."' method='post' enctype='multipart/form-data'>";
      echo "<table border='0' width='610'><tr>";
      echo "<td>年</td><td>月</td><td>日</td><td>天気</td><td>気候</td><td>日程</td><td>写真</td></tr><tr><td>";
      $year = date(Y);  
      echo "<input type='text' name='year' size='4'";
      echo "value=$year>年 </td>";
    /*------------------------------------------------*/
      echo "<td><select name='month'>";
      $cnt = 1;
      while ($cnt < 13){
        if($cnt == date(n)){
        echo "<option value='$cnt' selected>$cnt</option>";
        } else {
        echo "<option value='$cnt'>$cnt</option>";
        }
      $cnt++;
      }
      echo "</select></td>";
    /*------------------------------------------------*/
      echo "<td><select name='day'>";
        $sday = date(j);
        $op = 1;
        while($op <= 31){
          if($op == $sday){
          echo "<option value='$op' selected>".$op."日</option>¥n";
          } else {
          echo "<option value='$op'>".$op."日</option>¥n";
          }
          $op++;
        }
      echo "</select></td>";
    /*------------------------------------------------*/
      echo "<td><select name='weather'>";
      echo "<option value='9快晴'>快晴</option>";
      echo "<option value='8晴れ'>晴れ</option>";
      echo "<option value='7ほぼ晴れ' selected>ほぼ晴れ</option>";
      echo "<option value='6曇り'>曇り</option>";
      echo "<option value='5ドン曇り'>ドン曇り</option>";
      echo "<option value='4曇り/雨'>曇り/雨</option>";
      echo "<option value='3雨'>雨</option>";
      echo "<option value='2雪'>雪</option>";
      echo "<option value='1台風'>台風!</option>";
      echo "</select></td>";
    /*------------------------------------------------*/
      echo "<td><select name='air'>";
      echo "<option value='2激暑!'>激暑!</option>";
      echo "<option value='3暑い!'>暑い!</option>";
      echo "<option value='4暖かい'>暖かい</option>";
      echo "<option value='5爽やか' selected>爽やか</option>";
      echo "<option value='4涼しい'>涼しい</option>";
      echo "<option value='3やや寒い'>やや寒い</option>";
      echo "<option value='2寒い'>寒い</option>";
      echo "<option value='1激寒!'>激寒!</option>";
      echo "</select></td>";
    /*------------------------------------------------*/
      echo "<td><select name='act'>";
      echo "<option value='2畑仕事' selected>畑仕事</option>";
      echo "<option value='3自宅で勉強'>自宅で勉強</option>";
      echo "<option value='4家事'>家事</option>";
      echo "<option value='5港で釣り'>港で釣り</option>";
      echo "<option value='5競馬'>競馬</option>";
      echo "<option value='6遊びまくる'>遊びまくる</option>";
      echo "<option value='4引越しの手伝い'>引越しの手伝い</option>";
      echo "<option value='3会議'>会議</option>";
      echo "<option value='2芝刈り'>芝刈り</option>";
      echo "</select></td>";
    /*------------------------------------------------*/
      echo "<td><input type='file' name='pict' size='16'></td>";
      echo "<tr><td colspan='7'><textarea name='data' cols='82' rows='4'></textarea></td></tr>";
      echo "<tr><td><input type='submit' name='enter' value='記入'></td>";
      echo "<td><input type='submit' name='enter' value='削除'></td></tr></table></form>";
      $year = $_POST['year'];    //変更
      $month = $_POST['month'];
      $day = $_POST['day'];
      $weather = $_POST['weather'];
      $act = $_POST['act'];
      $air = $_POST['air'];
      $data = $_POST['data'];
      $enter = $_POST['enter'];
      $data = str_replace("¥n", '<br>', $data);
      $data = str_replace("&&", '', $data);
      $youbi = array("日曜日","月曜日","火曜日","水曜日","木曜日","金曜日","土曜日");
      $youbi_num = date(w,mktime(0,0,0,$month,$day,$year));
      $week_day = $youbi[$youbi_num];
      $weather_p = substr($weather,0,1);
      $air_p = substr($air,0,1);
      $act_p = substr($act,0,1);
      $weather = substr($weather,1);
      $air = substr($air,1);
      $act = substr($act,1);
      $point = $weather_p + $air_p + $act_p;
      $point = (int)($point/20*100);
      $save_data = $year."&&".$month."&&".$day."&&".$week_day."&&".$weather."&&".$air."&&".$act."&&".$data."&&".$point;
    /*----------------------------------------変更--------*/
      if(!file_exists("diary2/$year")){
        mkdir ("diary2/$year",0777);
      }
      $updir = "diary2/$year/month".$month;
      if(!file_exists($updir)){
        mkdir ($updir,0777);
      }
    /*------------------------------------------------*/
      $filename = $_FILES['pict']['name'];
      if(filename == null){
        $filename == "nowprint.jpg";
      }
    /*--------------------------------------------ここから削除部分----*/
      if ($enter == "削除" and $data == null){
        if(file_exists("./$updir/dairy$day")){  /*ファイルの存在を確認*/      
          $filepointer=fopen("./$updir/dairy$day", "r");
            $fileline = fgets($filepointer);
            $pictshow = split("##",$fileline);
            unlink("./$updir/$pictshow[0]");  /*ファイルを削除*/
          fclose($filepointer);
          unlink("./$updir/dairy$day");  /*ファイルを削除*/
        }
    /*------------------------------------------ここから書き込み部分------*/
      } else if($enter == "記入" and $data != null){
        if($updir != null){
          if(file_exists("./$updir/dairy$day")){
            echo "<font color='red'><b>その日の日記は既に記入済みです。</b></font><br><br>";
            echo "<div class='err'>$data</div>";
          } else if(file_exists($_FILES['pict']['tmp_name'])){
            $filesize = filesize($_FILES['pict']['tmp_name']);  /*ファイルサイズを取得 tempの状態で取得*/
            if($filesize <= 400000){
              if(ereg("(^[a-zA-Z0-9_-]+)¥.(jpg)|(^[a-zA-Z0-9_-]+)¥.(gif)",$filename)){  /*jpgかgifしかアップできない*/
                move_uploaded_file($_FILES['pict']['tmp_name'], "./$updir/$filename");  /*ファイルをフォルダに保存*/
              $filepointer=fopen("./$updir/dairy$day", "w+");
                flock($filepointer, LOCK_EX);
                  fputs($filepointer, $filename."##".$save_data);
                flock($filepointer, LOCK_UN);
              fclose($filepointer);
              } else {
              echo "jpg かgif のファイルしかアップできません。或いはハイフン以外の記号があります。<br><br>";
            echo "<div class='mess'>$data</div>";
              }
            } else {
              echo "$filesize Byte ファイルサイズが大きすぎます。<br>400kByte 以下にしてください。<br><br>";
            echo "<div class='mess''>$data</div>";
            }
          } else {
            echo "写真が指定されていません。<br><br>";
            echo "<div class='mess'>$data</div>";
          }
        }
      } else {
      echo " 記述済みを表示します。 ";
      }
    /*------------------------------------------ここから表示部分------*/
      echo $year."年 ".$month."月<br>";
      $count = 31;                
      while($count > 0) {
        if(file_exists("./$updir/dairy$count")){
          $filepointer=fopen("./$updir/dairy$count", "r");
            while(!feof($filepointer)){
              $fileline = fgets($filepointer);
              $pictshow = split("##",$fileline);
              $text = split("&&",$pictshow[1]);
              echo "<table width='610' bgcolor='#aadfff' border='0' ><tr><td>";
              echo "<table width='610' border='0' bgcolor='white'><tr>";
              echo "<td width='200' align='center' rowspan='2' valign='middle' bgcolor='#cdfaff'>";
              echo "<a href='$updir/$pictshow[0]' target='_blank'><img src='$updir/$pictshow[0]' border='0' width='200'>";
              echo "</a></td><td valign='top' height='5'><div class='waku'>";
              echo "<div class='top'>$text[0]年$text[1]月$text[2]日 $text[3]</div><div class='next'>";
              echo "$text[4] $text[5] $text[6] テンション $text[8] %<font color='#0000ff'></font></div>";
              echo "$text[7]</div></td></tr></table></td></tr></table><br>";
            }
          fclose($filepointer);
        }
      $count--;
      }
    }
    ?>

    </div>
    </body>
    </html>
    2019/1
    SUN MON TUE WED THU FRI SAT
        1 2 3 4 5
    6 7 8 9 10 11 12
    13 14 15 16 17 18 19
    20 21 22 23 24 25 26
    27 28 29 30 31   


     フォクすけ©2006 Mozilla Japan



    制作:基礎から解るPHP入門講座 代表:FREEZE

    Copyright © 2005/2/28 flzPHP.All Rights Riserved