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

Gordon
  • 312,688
  • 75
  • 539
  • 559
Robin Vekety
  • 89
  • 3
  • 9

3 Answers3

1

You have done wrong concatenation here

change this

echo readfile("$filename.txt");

to

readfile($filename . ".txt");
Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100
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!

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
-1

try this

<p>
<?php
  $filename = $_GET['package'].".txt";
  echo readfile($filename);
?></p>
deepi
  • 1,081
  • 10
  • 18