【问题标题】:Division by Zero in get_file_contentx() functionget_file_contentx() 函数中除以零
【发布时间】:2011-04-22 10:15:22
【问题描述】:

我有以下代码/脚本:

<?php
$file = $_GET[‘test.txt’];
$data = file_get_contents(‘/home/inftek2010/andreli/public_html/ift108/’.$file);
echo $data;
?>

当我尝试执行它时,我得到的只是一个错误提示:

警告:第 5 行 /home/inftek2010/andreli/public_html/ift108/testscript.php 中除以零

【问题讨论】:

  • 这些是您使用的一些特殊引号字符。你确定你不是指 '" 字符吗?

标签: php quotes


【解决方案1】:

您需要使用单引号 ' 代替您当前使用的倒引号。

为什么除以零误差?

PHP 允许倒引号 成为标识符/常量的一部分。所以

‘/home

被视为常量home 的除法。由于两者都没有定义,我们得到了通知,因为分母是0,我们得到了警告。

See this

【讨论】:

【解决方案2】:
<?php

//** Default value.
$data = "File not found.";

$file = '/home/inftek2010/andreli/public_html/ift108/'. $_GET["test.txt"];

    //** Confirm that file exists or not.
    if ( file_exists ($file) )      
        $data = file_get_contents($file);

echo $data;

?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多