PHP空白页面,但其他页面都可以使用


PHP Blank page but every other page works

这是我在错误日志中得到的错误

[Wed Mar 12 15:54:04.809152 2014] [:error] [pid 6111] [client] PHP Parse error:  syntax error, unexpected 'else' (T_ELSE) in /home/toolplas/public_html/main/new_incoming.php on line 354, referer: https://toolplas.com/post_file.php?job_num=1000

这很奇怪,因为这个页面在我的开发服务器上运行。

代码:

<?php
$page = 'New Incoming Data';
$renamed = false;
$post_array = array('folder' => null);
require_once('includes/config.php');
require_once('includes/auth.php');
if($loggedin) {
require_once('includes/header.php');
if(isset($_SESSION['new'])){
   $post_json = $_SESSION['post'];
   $new_json = $_SESSION['new'];
   unset($_SESSION['post']);
   unset($_SESSION['new']);
   $post_array = jsonDecode($post_json);
   $new_files_array = json_decode($new_json);
   if($debug){
      echo '<div style="margin-left:201px"><pre>';
         print_r($new_files_array);
      echo '</pre></div>';
      echo '<div style="margin-left:201px"><pre>';
         print_r($post_array);
      echo '</pre></div>';
   }
   $renamed = true;
   $url = stripcslashes($post_array['url']);
   require_once('/home/toolplas/public_html/Twig/Autoloader.php');
   Twig_Autoloader::register();
   $loader = new Twig_Loader_String();
   $twig = new Twig_Environment($loader);
}
?>
<script type='text/javascript'>
   $(document).ready(function(){
      $('#folder').html('');
      $('#folder').append('<option>Select</option>');
      $.ajax({
         url: 'phplib/list_folder.php',
         type: 'post',
         data: { date: $('#date').val()<?php
            /*if($renamed){
               echo ", current: '" . $post_array['folder'] . "'";
            }*/
            ?> },
         dataType: 'json',
         success: function(data){
            $.each(data, function(){
               if(this === '<?php echo $post_array['folder'] ?>'){
                  $('#folder').append('<option selected="selected" value="' + this + '">' + this + '</option>');
               } else {
                  $('#folder').append('<option value="' + this + '">' + this + '</option>');
               }
            })
         }
      });
      var parts = [ <?php echo getparts($dbc3); ?> ];
      //$('.part_input').autocomplete({ source: "phplib/json_search.php?table=indata_part_type&field=name" });
      $('#program').autocomplete({ source: "phplib/json_search.php?table=view_program&field=program" });
      $('#contact').autocomplete({ source: "phplib/json_search.php?table=indata_contacts&field=name" });
      $('#source').autocomplete({ source: "phplib/json_search.php?table=data_source&field=name" });
      $('#date').change(function(){
         $('#folder').html('');
         $('#folder').append('<option>Select</option>');
         $.ajax({
            url: 'phplib/list_folder.php',
            type: 'post',
            data: {
               date: $(this).val()
            },
            dataType: 'json',
            success: function(data){
               $.each(data, function(){
                  $('#folder').append('<option value="' + this + '">' + this + '</option>');
               })
            }
         });
      });
      $('#fetch').click(function(){
          $.ajax({
            url: "phplib/get_infiles2.php",
            type: "POST",
            data: {
                cust: $('#source').val(),
                date: $('#date').val(),
                folder: $('#folder').val(),
                intype: $('[name^=in_type]').serializeArray(),
                outtype: $('[name^=out_type]').serializeArray()
            },
            dataType: "html",
            success: function(data){
                $('#files').html(data);
            }
        });
      });
      $('.add_type').live('click',function(){
         $html = $(this).parent().html();
         $(this).parent().parent().append('<p>' + $html + '</p>');
      });
      /*$('#add_fease').live('click',function(){
         $.ajax({
            url: 'phplib/get_feases.php',
            type: 'post',
            data: {
               job_num: $('[name^=file]')
            },
            dataType: 'html',
            success: function(data){
               alert(data);
            }
         });
      });*/
      $('form').validate();
   });
</script>
<div id="content">
   <h2>New Incoming Data</h2>
   <form action='phplib/new_incoming.php' method='post'>
   <div id='indata'>
      <div id='formhead'>
         <div id='left' style='width:400px;'>
            <p>
               <label>Autogenerated Q Number</label>
               <input name='q_num' value="<?php if($renamed) echo $post_array['q_num']; else echo getnextqnum($dbc3); ?>" />
            </p>
            <p>
               <label>Data Source</label>
               <input name='source' id='source' value="<?php if($renamed) echo $post_array['source']; ?>" />
            </p>
            <p>
               <label>Date Received</label>
               <input name='date' id='date' class='datepicker' value="<?php if($renamed) echo $post_array['date']; else echo date(INPUT_DATE_FMT, strtotime('NOW')) ?>" />
            </p>
            <p>
               <label>Media</label>
               <select name='media' required>
                  <option value=''>Select</option>
                  <?php
                      $sql = "SELECT * FROM media";
                      $result = mysqli_query($dbc3, $sql);
                      while($row = mysqli_fetch_assoc($result)){
                          echo "<option";
                         if($renamed) if($post_array['media'] == $row['id']) echo " selected='selected'";
                          echo " value='" . $row['id'] . "'>" . $row['name'] . "</option>";
                      }
                  ?>
               </select>
            </p>
            <p>
               <label>Program</label>
               <input name='program' id='program' value="<?php if($renamed) echo $post_array['program']; ?>" />
            </p>
            <p>
               <label>Contact</label>
               <input name='contact' id='contact' value="<?php if($renamed) echo $post_array['contact']; ?>" />
            </p>
            <p>
               <label>Filename/PKG</label>
                    <?php if($renamed){
                  echo "<input type='text' name='folder' id='folder' readonly='readonly' value='" . $post_array['folder'] . "' />";
               } else { ?>
               <select name='folder' id='folder'>
                  <option>Select</option>
               </select>
                    <? } ?>
            </p>
         </div>
         <div id='right' style='margin-left:400px;'>
            <?php if($renamed){
               $in_type = $post_array['in_type'];
               $out_type = $post_array['out_type'];
               $intype = array();
               foreach($in_type as $key => $value){
                  $intype[] = $value['value'];
               }
               $outtype = array();
               foreach($out_type as $key => $value){
                  $outtype[] = $value['value'];
               }
               foreach($intype as $key => $value){
               ?>
               <p>
                  <label>In Type</label>
                  <select name='in_type[]'>
                     <?php
                         $sql = "SELECT * FROM datatype";
                         $result = mysqli_query($dbc3, $sql);
                         while($row = mysqli_fetch_assoc($result)){
                           echo "<option";
                             if($renamed) if($value == $row['id']) echo " selected='selected'";
                             echo " value='" . $row['id'] . "'>" . $row['name'] . "</option>";
                         }
                     ?>
                  </select>
                  <label>Out Type</label>
                  <select name='out_type[]'>
                     <?php
                         $sql = "SELECT * FROM datatype";
                         $result = mysqli_query($dbc3, $sql);
                         while($row = mysqli_fetch_assoc($result)){
                           echo "<option";
                             if($renamed){ if($outtype[$key] == $row['id']) echo " selected='selected'"; }
                             else{ if($row['name'] == 'Iges') echo " selected='selected'"; }
                             echo " value='" . $row['id'] . "'>" . $row['name'] . "</option>";
                         }
                     ?>
                  </select>
                  <a href='javascript:void()' class='add_type'>Add</a>
               </p>
               <?php }
            } else { ?><p>
               <label>In Type</label>
               <select name='in_type[]'>
                  <?php
                      $sql = "SELECT * FROM datatype";
                      $result = mysqli_query($dbc3, $sql);
                      while($row = mysqli_fetch_assoc($result)){
                        echo "<option";
                          if($renamed) if($post_array['data_type'] == $row['id']) echo " selected='selected'";
                          echo " value='" . $row['id'] . "'>" . $row['name'] . "</option>";
                      }
                  ?>
               </select>
               <label>Out Type</label>
               <select name='out_type[]'>
                  <?php
                      $sql = "SELECT * FROM datatype";
                      $result = mysqli_query($dbc3, $sql);
                      while($row = mysqli_fetch_assoc($result)){
                        echo "<option";
                          if($renamed){ if($post_array['data_type'] == $row['id']) echo " selected='selected'"; }
                          else{ if($row['name'] == 'Iges') echo " selected='selected'"; }
                          echo " value='" . $row['id'] . "'>" . $row['name'] . "</option>";
                      }
                  ?>
               </select>
               <a href='javascript:void()' class='add_type'>Add</a>
            </p>
            <?php } ?>
         </div>
         <div style='clear:both'></div>
         <input type='button' id='fetch' value='Fetch All The Things' />
      </div>
      <div id='files'>
      <?php if($renamed){ ?>
      <h2>Files</h2>
      <?php
         $indatatype = array();
   $sql = "SELECT * FROM datatype_extension";
   $result = mysqli_query($dbc3, $sql);
   while($row = mysqli_fetch_assoc($result)){
      if(in_array($row['datatype'], $intype)){
          $indatatype[] = $row['ext'];
      }
   }
   $datatype = array();
   foreach($in_type as $key => $value){
      $datatype[] = array('in' => $value['value'], 'out' => $out_type[$key]['value']);
   }
   //print_r($datatype);
   //echo $url;
   $files = array();
   if ($handle = opendir($url)) {
      $num = 0;
      while (false !== ($file = readdir($handle))) {
         if ($file != '.' && $file != '..' && $file != 'Thumbs.db' && !is_dir("$url/$file")){
            if(in_array(strtolower(pathinfo("$url/$file", PATHINFO_EXTENSION)), $indatatype)){
               foreach($intype as $key => $value){
                  if(getfileext($value) == strtolower(pathinfo("$url/$file", PATHINFO_EXTENSION))){
                     $in = $value;
                     $out = $outtype[$key];
                  }
               }
               $files[] = array('o_name' => $file, 'outtype' => $out, 'intype' => $in, 'size' => number_format(filesize("$url/$file")));
            }
         }
      }
   }
   $part_type = array();
   $sql = "SELECT * FROM indata_part_type";
   $result = mysqli_query($dbc3, $sql);
   while($row = mysqli_fetch_assoc($result)){
       $part_type[] = array('name' => $row['name'], 'id' => $row['id']);
   }
$html = <<<EOF
   <table class='fancy'>
      <thead>
         <tr>
            <th></th>
            <th>Job Number</th>
            <th>New File Name</th>
            <th>Original File Name</th>
            <th>File Size</th>
            <th>Part</th>
            <th>Part Number</th>
            <th>Description</th>
         </tr>
      </thead>
      <tbody>
         {% for item in files %}
            <tr>
               <td style='text-align:center;'><input type='checkbox' name="file[{{ loop.index }}][active]" value='YES' checked='checked' style='width:20px;'  /></td>
               <td><input style='width:100%;' name="file[{{ loop.index }}][job_num]" value='{{ item.job_num }}' /></td>
               <td><input style='width:100%;' class='unique' name="file[{{ loop.index }}][n_file]" value='{{ item.n_file }}' /></td>
               <td>{{ item.o_file }}<input type='hidden' name="file[{{ loop.index }}][o_file]" readonly='readonly' value='{{ item.o_file }}' /></td>
               <td>{{ item.size }}<input type='hidden' name="file[{{ loop.index }}][size]" readonly='readonly' value='{{ item.size }}' /></td>
               <td><select name="file[{{ loop.index }}][part]">
                  <option value=''>Select</option>
                  {% for part in parts %}
                  <option value='{{ part.id }}'{% if item.part == part.id %} selected='selected'{% endif %}>{{ part.name }}</option>
                  {% endfor %}
               </select></td>
               <td><input style='width:100%;' name="file[{{ loop.index }}][part_num]" value='{{ item.part_num }}' /></td>
               <td><input style='width:100%;' name="file[{{ loop.index }}][desc]" value='{{ item.desc }}' /></td>
               <input type='hidden' name='file[{{ loop.index }}][outext]' value='{{ item.outext }}' />
               <input type='hidden' name='file[{{ loop.index }}][inext]' value='{{ item.inext }}' />
               <input type='hidden' name='file[{{ loop.index }}][version]' value='{{ item.version }}' />
            </tr>
         {% endfor %}
      </tbody>
   </table>
   <input type='hidden' name='url' value='{{ url }}' /><input type='submit' name='rename' value='Rename' /> <input type='submit' name='add_fease' id='add_fease' value='Add Fease' /> <input type='submit' name='submit' id='submit' value='Submit' />
EOF;
   echo $twig->render( $html, array('files' => $new_files_array, 'parts' => $part_type, 'url' => $url) );
       } ?>
      </div>
   </div>
   </form>
</div>
<?php
  require_once('includes/footer.php');
  } else echo showlogin();
?>

抱歉时间太长了。它抱怨的其他问题在文件的最后。有人知道线索吗?

您的问题在第170行:

                <? } ?>

请注意,这里有一个简短的open标记:<?而不是<?php。我可以重现您的解析错误,并通过将open标记替换为完整的<?php open标记来消除它。

因此,我推断您的生产服务器没有打开short_open_tag。如果要在生产服务器上禁用short_open_tag,则应确保在开发服务器上禁用它。

我还建议研究更结构化的PHP开发实践——可能是通过查看一些现有的顶级框架——看看你是否能得到一些关于如何降低代码复杂性的提示。PHP、HTML、jQuery、Mustache和样式属性的混合可能会更好地用CSS处理,所有这些都在一个大文件中,似乎很难处理。