开发者

Division by Zero in get_file_contentx() function

I've got the following code/script:

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

When I try to execute it all i get is an error saying:

Warning: Division by zero in /home/inftek2010/andreli/public_html/ift108开发者_Python百科/testscript.php on line 5


You need to use single quotes ' in place of inverted quotes that you're currently using.

Why divide by zero error?

PHP allows the inverted quotes to be part of identifier/constants. So

‘/home

is treated as division of constants and home. Since both are not defined we get Notice and since the denominator is 0 we get the warning.

See this


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

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜