Jump to content

how do you use php functions to link to a file with the url of the php?


ted_chou12

Recommended Posts

okay,
lets say i have a text file called "info1.txt" and another one called "info2.txt"
I want a php page that includes the file "info1.txt", and I want a id url address for this.
however, I also want this php page to include "info2.txt" with another id url adress.
id url can be anything like this:
http://test.com/page.php?id=info1
http://test.com/page.php?id=info2
but I just want each of the php page to include each of the two text separatly, so when "http://test.com/page.php?id=info1" is entered in the browser, the php page only shows up "info1.txt", while when "http://test.com/page.php?id=info2" is entered, the php page only shows up the "info2.txt".

(Understand now?)
[code]
<?php

$file = $_GET["id"] . ".txt";

$open = fopen($file, "r");

print "<pre>";
print (file_get_contents($file));
print "</pre>";

fclose($open);

?>[/code]

That will do what you want.
example. page.php?id=hello
Will produce text file: hello.txt

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.