繁体   English   中英

HTML / php解析器错误

[英]HTML/php Parser error

我正在浏览位于http://net.tutsplus.com/tutorials/php/online-file-storage-with-php/comment-page-2/#comments的教程,并且在以下情况下都可以正常工作:

if(strlen($message) > 0)
{
    $message = '<p class="error">' . $message . '</p>';
}

这行php可在index.php中找到。 当我在firefox中浏览几页时,看起来php解析器停在了大于。 我可以逃脱角色吗? 我需要吗?

编辑:所有php代码:

<?php 
//Load the settings
require_once("settings.php");

$message = "";
//Has the user uploaded something?
if(isset($_FILES['file']))
{
    $target_path = Settings::$uploadFolder;
    $target_path = $target_path . time() . '_' . basename( $_FILES['file']['name']); 

    //Check the password to verify legal upload
    if($_POST['password'] != Settings::$password)
    {
        $message = "Invalid Password!";
    }
    else
    {
        //Try to move the uploaded file into the designated folder
        if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
            $message = "The file ".  basename( $_FILES['file']['name']). 
            " has been uploaded";
        } else{
            $message = "There was an error uploading the file, please try again!";
        }
        }

    //Clear the array
    unset($_FILES['file']);
}


if(strlen($message) > 0)
{
    $message = '<p class="error">' . $message . '</p>';
}    
?>
<html> ... </html> //my html code

>不会导致PHP解析器停止。

在没有看到服务器输出的HTML的情况下,很难确定,但是由于>是文件中的第一个> ,因此PHP解析器似乎永远不会启动 ,浏览器一开始会处理<?php之间的所有内容。文件和strlen($message) > 作为标签

您需要通过安装了PHP并配置为处理该文件的Web服务器来访问PHP(通常通过给该文件提供.php文件扩展名来完成)。

那这个呢?

if(!empty($message)){
    $message = '<p class="error">'.$message.'</p>';
}

但是,为什么不直接将段落标签分配给错误消息,而不是先将错误消息分配给$message然后分配段落标签呢?

如果条件正常,则没有任何错误

在此处输入图片说明

可能的问题

  1. if(isset($_FILES['file']))
  2. if($_POST['password'] != Settings::$password)
  3. if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path))

如果您没有进入if主体,则意味着存在问题

  if(isset($_FILES['file']))

因为如果它比$message = "";更容易$message = "";

始终使用Yoda条件并以相反的顺序编写这样的语句(通常习惯于:

if ( 0 !== strlen( $message ) )
{
    $message = 'Hello World!';
}

无论如何,您也可以简单地检查! empty( $message ) ! empty( $message )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM