HTMLからPOSTで送信したデータがphpでは空になっている...
php初心者です。
ある程度理解したので自作のブログ投稿システムを作ってみたのですがhtmlからPOSTで送ったデータがphpでは殻になっています。
どうしたら良いのでしょうか?
new.html
1<html> 2<body> 3<head> 4 <meta charset="utf-8"> 5 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 6 <meta name="description" content=""> 7 <meta name="author" content=""> 8 <meta name="viewport" content="width=device-width, initial-scale=1"> 9 <link rel="icon" href="homepage.ico"> 10</head> 11<form action="http://localhost/makefile.php" method="POST"> 12 <label>タイトル名</label><br> 13 <input type="text"class="title" name="title"><br/> 14 <label>本文</label><br> 15 <textarea class="text" name="honbun" rows="20" cols="200"></textarea> 16 <table> 17 <tr> 18 <th><label>タイトルカラー</label></th> 19 <td><input type="color" name="titlecolor"></td> 20 </tr> 21 <tr> 22 <th><label>本文の文字色</label></th> 23 <td><input type="color" name="honbuncolor"></td> 24 </tr> 25 <tr> 26 <th><label>バックカラー</label></th> 27 <td><input type="color" name="backcolor" value="#FFFFFF"></td> 28 </tr> 29 <tr> 30 <th><label>フォント</label></th> 31 <td><input type="text" name="font"></td> 32 </tr> 33 <tr> 34 <th><label>フォントサイズ</label></th> 35 <td><input type="text" name="fontsize"></td> 36 </tr> 37 <tr> 38 <th><label>テンプレートファイル</label></th> 39 <td><input type="file" name="template"></td> 40 </tr> 41</table> 42 <center><input type="submit" value="送信"></center> 43</form> 44 45<style> 46 label { 47 margin-left: 30%; 48 } 49 .text{ 50 margin-left: 10%; 51 } 52 .title { 53 margin-left: 29%; 54 } 55 textarea { 56 font-family: '游明朝'; 57 font-weight: bold; 58 } 59 table { 60 margin-left: 15%; 61 } 62</style> 63</body> 64</html>
なお、ローカル環境で実行すると成功するのですがサーバー環境で実行すると失敗します
makefile.php
1<html> 2<head> 3<title>ブログ作成</title> 4<meta charset="utf-8"> 5</head> 6<body> 7<?php 8if (!empty($_POST)) { 9 if ($_POST["honbun"] != "") { 10 echo $_POST["honbun"] 11 } 12} 13if (isset($_POST['template'])) { 14 $template = $_POST['template']; 15} else { 16$template = 'template.php';} 17if (isset($_POST['title'])) { 18 $pagetitle = $_POST['title']; 19} else { 20 $pagetitle = 'デフォルト'; 21} 22if (isset($_POST['honbun'])) { 23$honbun = $_POST['honbun']; 24$honbuncolor = $_POST['honbuncolor']; 25$titlecolor = $_POST['titlecolor']; 26$backcolor = $_POST['backcolor']; 27$font = $_POST['font']; 28$fontsize = $_POST['fontsize']; 29$honbun = htmlspecialchars($honbun); 30$honbun = str_replace('./','<b>',$honbun); 31$honbun = str_replace('/.','</b>',$honbun); 32$honbun = str_replace('.!b','<big>',$honbun); 33$honbun = str_replace('.b!','</big>',$honbun); 34$honbun = str_replace('!b','<big><big><big><big><big><big><big><big><big><big>',$honbun); 35$honbun = str_replace('b!','</big></big></big></big></big></big></big></big></big></big>',$honbun); 36$honbun = nl2br($honbun); 37$filename = rand( 1000000, 9999999) . ".html"; 38// ※4 テンプレートファイルの読み込み 39$contents = file_get_contents( $template); 40// ※5 タイトルと記事本文を挿入 41$contents = str_replace( "<%PAGETITLE>", htmlspecialchars($pagetitle), $contents); 42$contents = str_replace( "<%PAGECONTENTS>", $honbun, $contents); 43$contents = str_replace('<%honbuncolor>',$honbuncolor,$contents); 44$contents = str_replace('<%titlecolor>',$titlecolor,$contents); 45$contents = str_replace('<%backcolor>',$backcolor,$contents); 46$contents = str_replace('<%font>',$font,$contents); 47$contents = str_replace('<%fontsize>',$fontsize,$contents); 48$contents = str_replace("<%filename>",$filename,$contents); 49$handle = fopen($filename,'w'); 50fwrite($handle,$contents); 51fclose($handle); 52echo "<center><b>".$pagetitle. "<b>の投稿が完了しました</center>"; 53echo "<a href='".$filename."'>".$pagetitle."<a>"; 54} else { 55 echo "フォームから記事の内容を送信してください。"; 56} 57?> 58</body> 59</html>
ブラウザの開発者モードでネットワークを見てみるとちゃんと送信されています。
phpからPOSTを確認すると配列自体は受け取れていますが値がありません。
調べた限りの解決策を試しましたが効果がありません
どうすればいいのでしょうか?
回答4件