概要
目標動作
HTMLを打ち込む(Textarea)⇒
①提出ボタン⇒サーバーの個人フォルダに.htmlファイルとして保存 [PHP]
②プレビューボタン⇒Textareaのテキスト抽出⇒プレビュー領域に表示
作業
久々のコーディング。記憶の穴が多すぎる。笑
リファレンス見る時間が長い。デバッグの仕方すら忘れかけ。
CSSなどビジュアルの調整ができてないので、表示はまだズレズレだけど基本仕様の動作はできた。
次は、
- 進捗状況を見るための教員用GUI
- 生徒認証ページ(学籍番号or年組番の認証)
二学期まであと3週間!
⓪コンフィグファイル
<?php $root = "C:/MAMP/htdocs"; function console_log( $data ){ echo '<script>'; echo 'console.log('. json_encode( $data ) .')'; echo '</script>'; } ?>
①HTMLコード提出画面(生徒GUI)
<?php include("./config.php"); console_log( $myvar ); // [1,2,3] ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>ファイル提出画面</title> </head> <body> <h1>提出結果、GET受信</h1> <?php $std_num = $_GET['nen'] . $_GET['kurasu'] . $_GET['snum1'] . $_GET['snum2']."/"; $dir_path = $root."/seito/". $std_num; //作成ディレクトリのパス if(file_exists($dir_path)){ echo "フォルダ有<br>"; }else{ if(mkdir($dir_path, 0777)){//0777は権限制限なしに設定 //作成に成功した時の処理 echo "フォルダ新規作成<br>"; }else{ //作成に失敗した時の処理 echo "作成に失敗しました<br>"; } } $content = $_GET['code']; console_log($content); console_log($dir_path); if( is_writable($dir_path) ) { if(file_put_contents( $dir_path."index1.html", $content)){ console_log("書き込み成功"); }; } ?> </body> </html>
②提出処理(内部動作用/結果表示GUI)
<?php include("./config.php"); console_log( $myvar ); // [1,2,3] ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>ファイル提出画面</title> </head> <body> <h1>提出結果、GET受信</h1> <?php $std_num = $_GET['nen'] . $_GET['kurasu'] . $_GET['snum1'] . $_GET['snum2']."/"; $dir_path = $root."/seito/". $std_num; //作成ディレクトリのパス if(file_exists($dir_path)){ echo "フォルダ有<br>"; }else{ if(mkdir($dir_path, 0777)){//0777は権限制限なしに設定 echo "フォルダ新規作成<br>"; }else{ echo "作成に失敗しました<br>"; } } $content = $_GET['code']; console_log($content); console_log($dir_path); if( is_writable($dir_path) ) { if(file_put_contents( $dir_path."index1.html", $content)){ console_log("書き込み成功"); echo "ファイルが保存されました。"; }; } ?> </body> </html>