2013-07-25 3 views
0

나는 그것을 작동 시켰고 어느 시점에 어제 그것을 깨뜨렸고 알아 ​​내지 못했습니다.두 번째까지 PHP 코드가 실행되지 않습니다.

양식 입력에서 html 파일을 생성 중입니다.

데이터가 페이지에 게시되었지만 양식이 처음 제출 될 때 "foreach"루프가 실행되지 않는 경우 함수를 호출합니다. 이후에 3 개의 이미지를 업로드하면 1 개의 자산이 부끄러워집니다. '

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 페이지를 생성하고 모든하지만 형태를 눌러를 제출 한 후 F5를 누르면 처음이 ... $ 내용이 비어 실행 ... 생성 된 페이지의 2를 보여줄 것이다 계속해서 데이터를 다시 제출하라는 메시지가 나오면 foreach 루프에서 코드를 실행하고 $ content는 html의 위쪽과 아래쪽 사이에있는 문자열을 포함합니다 .......

어떤 아이디어가 그럴 수 있니?

+8

그 코드를 찾은 후 나는 두통이있다 ... – Alvaro

+0

다음과 같은 코드가있다 : mysql_connect ('localhost', 'dbname', 'pw'); mysql_select_db ('tablename'); // select file' mysql_connect()의 두 번째 매개 변수는 사용자 이름이어야하며 mysql_select_db()는 데이터베이스의 이름이어야한다. –

+0

^실수로 내 암호/사용자 이름 테이블 이름을 가져 왔을 때 코드에서 올바르다. $ 콘텐츠 변수가 두 번째로 만 채워진 것처럼 보입니다 ... 알아낼 수는 없습니다 ... – user1108224

답변

0

몇 가지 기능으로 나누고 순서를 지정하여 작동 시켰습니다.

관련 문제