-2
<p>
<?php
$filename = $_GET['package'];
echo readfile("$filename.txt");
?></p>

This is a part of my html, and I want to use this url to read the filename of a txt:

http://example.com/something.html?package=new

if I am using this, the html must show the contents of new.txt, but nothing.

I've set error_reporting(-1) but there is no error.

The URL is http://repo.cydie.com/depictions/2.html just see the source code

What was my error?

4

3 回答 3

1

You have done wrong concatenation here

change this

echo readfile("$filename.txt");

to

readfile($filename . ".txt");
于 2013-05-03T12:38:20.027 回答
0

you need no echo for readfile. readfile() will output the contents directly

readfile("$filename.txt");

Manual:

Reads a file and writes it to the output buffer.

Note that this causes problems as readfile() will return the number of bytes read from the file. So your content - if exist - will look like:

hello world
12 

(note the linefeed, that's why 12, not 11)


But this doesn't cause the problem, that the file isn't found. You should check if $filename really exists!

于 2013-05-03T12:39:07.353 回答
-1

try this

<p>
<?php
  $filename = $_GET['package'].".txt";
  echo readfile($filename);
?></p>
于 2013-05-03T12:38:23.340 回答