私はそれを機能させていましたが、ある時点で昨日それを壊してしまい、それを理解できません。
フォーム入力からhtmlファイルを生成しています。
データがページに投稿された場合は関数を呼び出しますが、フォームが最初に送信されたときに「foreach」ループが実行されません...そして、その後は恥ずかしがり屋の1つのアセットです。3つの画像をアップロードすると、2が表示されます生成されたページで...
function AddClientDB($client, $pth, $project){
mysql_connect('localhost', 'dbname', 'pw'); //connect to db
mysql_select_db('tablename'); //select file
$indx = $project.".html";
$sql="INSERT INTO Clients VALUES (NULL,'$client', '$project', 'http://webpage.net/','$pth','$indx')";
mysql_query($sql) or DIE("Problems with the query:<pre>$sql</pre>" . mysql_error());
//Create client folder
if (!file_exists('uploads/'.$client)) {
mkdir('uploads/'.$client, 0777, true);
echo "Created Folder for Client: ". $_GET['client']. "<br />";
}
//Make project folder under client
if (!file_exists('uploads/'.$client. '/'. $project)) {
mkdir('uploads/'.$client.'/'.$project, 0777, true);
}
$sql="INSERT INTO Projects VALUES (NULL,'$project', '$client',0,0,'$pth')";
mysql_query($sql) or DIE("Problems with the query:<pre>$sql</pre>" . mysql_error());
$myFile = 'uploads/'.$client.'/'.$project . '/' . $project.".html";
$fh = fopen($myFile, 'w') or die("can't open file");
//Top part of html page to make
$stringDataA = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Title</title>
<link rel="stylesheet" type="text/css" href="http://pixelfirereview.net/styles.css">
<script type="text/javascript">
function popDate(){
var dt=new Date();
document.getElementById("dat").innerHTML=dt;
}
</script>
</head>
<body onload="popDate();">
<div align="center">
<table width="960" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="960" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="480"></td>
<td width="480"><a href="dbview.php" target="_blank"><img src="http://www.pixelfireinc.com/pfp2011/wp-content/uploads/2011/04/PixelfireLogoTopSM1.png" width="340" height="72" border="0" align="right" /></a></td>
</tr></table></td></tr><tr><td> </td></tr><tr><td>
<table width="960" border="0" cellspacing="0" cellpadding="0"><tr>
<td><div align="center"</div></td></tr><tr>
<td><div align="center">';
//Foreach valid file in the project folder, add it to our $content variable as a string.
//For some reason, the foreach loops only run the second time the form is submitted...if you hit f5 and continue through the warning about resubmitting data, it then fires the code in the foreach loops....
foreach (glob($pth. '*.jpg') as $filename2) {
echo "<br />filename2: ". $filename2. "<br />";
// echo "<br />$filename size " . filesize($filename2) . "<br />";
$content = $content . '<span class="m_title">'.$filename2.'</span><br /><p><img src="http://pixelfirereview.net/'.$filename2.'" /><br /><br /><a href="http://pixelfirereview.net/'.$filename2.'"><img src="http://pixelfire.net/clients/images/btn_download.png" width="235" height="50" border="0" align="right" /></a></p><br />';
}
foreach (glob($pth. '*.png') as $filename3) {
echo "<br />filename3: ". $filename3."<br />";
echo "<br />\n$filename size " . filesize($filename3) . "<br />";
$content = $content . '<br /><span class="m_title"><!-- InstanceBeginEditable name="Project Title" -->'.$filename3.'</span><img src="http://pixelfirereview.net/'.$filename3.'" />
<br /><br /><p><a href="http://pixelfirereview.net/'.$filename3.'"><img src="http://pixelfire.net/clients/images/btn_download.png" width="235" height="50" border="0" align="right" /></a></p><br />';
}
foreach (glob($pth. '*.mp4') as $filename4) {
echo "<br />filename4: ". $filename4."<br />";
// echo "<br />\n$filename size " . filesize($filename4) . "<br />";
$content= $content. '<br /><span class="m_title">'.$filename4.'</span><div id="mediaplayer'.$filename4.'"></div><script type="text/javascript" src="http://www.pixelfire.net/clients/jwplayer.js"></script><script type="text/javascript">
jwplayer("mediaplayer'.$filename4.'").setup({
flashplayer: "http://www.pixelfire.net/clients/player.swf",
file: "http://pixelfirereview.net/'.$filename4.'",
width: "960",
height: "565",
autoplay: "false",
image: "http://www.pixelfire.net/clients/images/VideoPreview.jpg",
repeat: "always",
controlbar: "bottom",
});
</script><br />
<p><a href="http://pixelfirereview.net/'.$filename4.'"><img src="http://pixelfire.net/clients/images/btn_download.png" width="235" height="50" border="0" align="right" /></a></p><br />';
}
foreach (glob($pth. '*.wav') as $filename5) {
$content = $content . '<span class="m_title">'.$filename5.'</span><div id="mediaplayer'.$filename5.'"></div> <script type="text/javascript" src="http://www.pixelfire.net/clients/jwplayer.js"></script> <br /><script type="text/javascript">
jwplayer("mediaplayer'.$filename5.'").setup({
flashplayer: "http://www.pixelfire.net/clients/player.swf",
file: "http://pixelfirereview.net/'.$filename5.'",
width: "960",
height: "565",
autoplay: "false",
image: "http://www.pixelfire.net/clients/images/VideoPreview.jpg",
repeat: "always",
controlbar: "bottom",
});
</script><br />
<p><a href="http://pixelfirereview.net/'.$filename5.'"><img src="http://pixelfire.net/clients/images/btn_download.png" width="235" height="50" border="0" align="right" /></a></p>';
}
//Create the lower half of the html page
$stringDataB= '</div></td></tr><tr><td height="20"> </td></tr><tr><td><table width="960" border="0" cellspacing="0" cellpadding="0"><tr>
<td width="620" valign="top"><table width="550" border="0" cellspacing="0" cellpadding="1"><tr>
<td width="125" class="m_main"><div align="right">Last Modified:</div></td>
<td width="400"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>
<div id="dat" style="margin-top:80px;background:#333333;padding:.5em;" align="left" class="m_main_alt"></div></div></td></tr></table></td></tr></table></td><td width="350" valign="top">
<table width="350" border="0" cellspacing="1" cellpadding="0"><tr>
<td></td>
</tr></table></td></tr></table></td></tr><tr><td height="100"></td></tr></table></td></tr><tr><td></td></tr><tr><td>
<div align="center" class="footer">© 2013 PixelFire Productions<br /> (425) 917-1400 </div></td> </tr> </table></div></body></html>';
//Put the pieces together, top html, content, bottom html.
$stringData = ''.$stringDataA . $content . $stringDataB.'';
fwrite($fh, $stringData);
}
HTMLページとすべてを作成しますが、最初に実行すると$ contentは空です....フォームを送信した後にF5を押し、データの再送信に関するメッセージで続行を押すと、foreachループでコードが実行され、 $content には、html の上半分と下半分の間に配置される文字列が含まれます.......
なぜそれが考えられるのか?