在get_file_contentx()函数中除以零

时间:2011-04-22 10:15:22

标签: php quotes

我有以下代码/脚本:

<?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中除以零

2 个答案:

答案 0 :(得分:5)

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

为什么除以零错误?

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

‘/home

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

See this

答案 1 :(得分:0)

<?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;

?>
相关问题