【问题标题】:php project deployment new problemphp项目部署新问题
【发布时间】:2009-09-02 19:36:17
【问题描述】:

我已经完成了一个 php 项目,我已经将它上传到服务器上。我已经在 windows 上开发了它,现在我正在尝试将它部署在远程 linux 服务器上。但我收到错误。 页面的某些部分没有显示我不知道为什么? 例如,我有一页应用如下。我只能看到顶部,其他部分我看不到。

<?php 
require 'inc/header.php';
require 'inc/config.php';
require 'inc/functions.php';



$QUERY0 = "
            SELECT *
            FROM states
          ";

       $result0 = send_query($QUERY0);
       $i=0;
       while($row = mysql_fetch_array($result0))
            {
                $states_names[$i]=$row['sname'];
                $states_val[$i] =$row['id'];
                $i++;

            }

$QUERY1 = "
            SELECT *
            FROM courses
          ";

       $result1 = send_query($QUERY1);
       $i=0;
       while($row = mysql_fetch_array($result1))
            {
                $courses_names[$i]=$row['cname'];
                $courses_val[$i]=$row['id'];
                $i++;

            }


$QUERY2 = "
            SELECT *
            FROM jobprofile
          ";

       $result2 = send_query($QUERY2);
       $i=0;
       while($row = mysql_fetch_array($result2))
            {
                $jobprofiles_names[$i]=$row['jobname'];
                $jobprofile_val[$i]=$row['jobid'];
                $i++;

            }



$QUERY3 = "
            SELECT *
            FROM edu
          ";

       $result3 = send_query($QUERY3);
       $i=0;
       while($row = mysql_fetch_array($result3))
            {
                $edu_names[$i]=$row['eduq'];
                $edu_val[$i]=$row['id'];


              //  echo "***********" .$edu_names[$i];
                $i++;

            }






?>

<div class="left">
    <div class="left_articles">

        <h2><a href="#">Register</a></h2>
        <p class="description">Please submit the folloing form</p>
        <p>
            <form action="check.php" method="post">

            <table border="0">

                <tbody>
                    <tr>
                        <td>First name</td>
                        <td><input type="text" name="fname" value="" /></td>
                    </tr>
                    <tr>
                        <td>Last name</td>
                        <td><input type="text" name="lname" value="" /></td>
                    </tr>
                    <tr>
                        <td>Address</td>
                        <td><input type="text" name="address" value="" /></td>
                    </tr>

                    <tr>
                        <td>age</td>
                        <td><input type="text" name="age" value="" /></td>
                    </tr>

                    <tr>
                        <td>State of origin</td>
                        <td>
                            <select name="origin">
                                <?  $i=0;
                                    foreach( $states_names as $state )
                                    {

                                        $val=  $states_val[$i] ;
                                ?>
                                <option value="<? echo $val; ?>"><? echo $state; ?> </option>
                                <?
                                        $i++;
                                    }
                                ?>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>Mobile no</td>
                        <td><input type="text" name="mobile" value="" /></td>
                    </tr>
                    <tr>
                        <td>Sex</td>
                        <td><select name="sex">
                                <option value="1">Male</option>
                                <option value="0">Female</option>
                        </select></td>
                    </tr>
                    <tr>
                        <td>Marrital Status</td>
                        <td><select name="ms">
                                <option value="0">Single</option>
                                <option value="1">Married</option>
                        </select></td>
                    </tr>
                    <tr>
                        <td>Email</td>
                        <td><input type="text" name="email" value="" /></td>
                    </tr>
                    <tr>
                        <td>Job Applying For</td>
                        <td><select name="jobtype">
                                 <?  $i=0;
                                    foreach( $jobprofiles_names as $job )
                                    {

                                        $val=  $jobprofile_val[$i] ;
                                ?>
                                <option value="<? echo $val; ?>"><? echo $job; ?> </option>
                                <?
                                        $i++;
                                    }
                                ?>
                        </select>
                        </td>
                    </tr>

                    <tr>
                        <td>Have u worked in this sector before</td>
                        <td><select name="exp">
                                <option value="0">no</option>
                                <option value="1">yes</option>

                        </select></td>
                    </tr>
                    <tr>
                        <td>Which department of this sector u have worked?</td>
                        <td>    <input type="text" name="exptype" value="" />

                       </td>

                    </tr>
                    <tr>
                        <td>Years of experinece in this sector</td>
                        <td><input type="text" name="yrsexp" value="" /></td>
                    </tr>

                    <tr>
                        <td>Higest Educational qualification</td>
                        <td><select name="eduq">
                                <?  $i=0;
                                    foreach( $edu_names as $ed)
                                    {

                                        $val=  $edu_val[$i];
                              ?>
                                <option value="<? echo $val; ?>"><? echo $ed; ?> </option>
                               <?
                                        $i++;

                                    }
                               ?>
                        </select>

                        </td>
                    </tr>

                    <tr>
                        <td>Course taken in above educational qualification</td>
                        <td><select name="crc">

                              <?  $i=0;
                                    foreach( $courses_names as $crc)
                                    {

                                        $val=  $courses_val[$i];
                              ?>
                                <option value="<? echo $val; ?>"><? echo $crc; ?> </option>
                               <?
                                        $i++;

                                    }
                               ?>
                        </select>

                        </td>
                    </tr>

                    <tr>
                        <td>Grade obtained in the above educational qualification</td>
                        <td><select name="grade">
                                <option value="0">A</option>
                                 <option value="1">B</option>
                                  <option value="2">C</option>
                                   <option value="3">D</option>

                        </select>

                        </td>
                    </tr>


                    <tr>
                        <td></td>
                        <td><input type="submit" value="Apply now" /></td>
                    </tr>
                </tbody>
            </table>
            <input type="hidden" name="action" value="check" />
             </form>

        </p>
    </div>


</div>  



<?  require 'inc/right.php'  ?>

<?  require 'inc/footer.php'  ?>

我的文件描述如下。 标头包含标头 right.php 包含页面的右侧

为什么我的页面没有完全显示?斜线/位置有问题吗? windows 和 linux 有区别吗?

【问题讨论】:

    标签: php windows linux deployment


    【解决方案1】:

    文件系统中inc和inc/headers.php的文件和目录都是小写的吗? Unix 文件名区分大小写。将包含更改为 require 以查看它是否会导致错误。

    【讨论】:

      【解决方案2】:

      您正在体验 Windows 和 Linux 处理相对路径的方式不同。

      使用绝对路径(注意,Windows 和 Linux 上的 php 都接受正斜杠目录分隔符)。

      假设(Linux 服务器示例)您的应用程序始终从绝对路径执行:

      /home/www/index.php  
      

      您的包含脚本位于:

      /home/www/inc/header.php  
      

      ...

      然后你可以定义一个绝对路径并将其连接到每个包含字符串:

      <?php
      
      define('ABSPATH', dirname(__FILE__));
      
      ...
      
      include ABSPATH . '/inc/header.php';  
      
      ...
      
      include ABSPATH . '/inc/footer.php';
      
      ?>
      

      【讨论】:

        【解决方案3】:

        您还应该检查所有文件中的行尾。如果你是在 Windows 上开发的,你的文件中很有可能出现 cr/lf 行结尾,甚至是混合状态。根据您将文件传输到 Linux 服务器的方式,它们可能会被转换或不转换。尤其是混合状态会造成麻烦。

        另一个检查是文件的编码 - 这些也应该在整个项目中保持一致。如果它们使用 UTF-8,请确保它们没有 Byte-order mark (BOM),因为这可能会导致包含的文件出现问题。

        【讨论】:

          【解决方案4】:

          “顶部”是什么意思?

          另外,尝试更改您的 php 标签以明确将自己标记为 php,所以

          <?php ... ?>
          

          而不是

          <? ... ?>
          

          【讨论】:

            【解决方案5】:

            DIRECTORY_SEPARATOR 常量将在这里为您提供帮助。

            替换:

            require 'inc/header.php';
            

            与:

            require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'header.php';
            

            其余的也做类似的事情。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2023-03-18
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2013-01-14
              相关资源
              最近更新 更多