0

我让它工作了,昨天在某个时候把它弄坏了,无法弄清楚。

我正在从表单输入生成一个 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>&nbsp;</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">&nbsp;</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">&copy; 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 并在有关重新提交数据的消息处按 Continue,然后它会在 foreach 循环中运行代码并$content 将包含一个放在 html 上半部和下半部之间的字符串......

任何想法为什么会这样???

4

1 回答 1

0

通过将其拆分为几个函数并强制执行命令来使其工作。

于 2013-07-25T17:27:29.930 回答