Forum Moderators: coopster
This way is ok, however it can create some unwanted security issues.
eelix
1. How do I reference (call?) this line of code in the URL?
2. How do I add this code to the page? Just like this:
<?php
$text = @file_get_contents("$_GET['file_name']") or die("File not found!");
?>
3. Also do I swap 'file_name' for the path to where the file is?
>>>2. How do I add this code to the page? Just like this:
Just like this:
<?php
$text = @file_get_contents("http://yoursite.com/$_GET['file_name']") or die("File not found!"); //i added this so that it comes from your server and not someone elses
?>
>>>3. Also do I swap 'file_name' for the path to where the file is?
refer to question 1. You would replace 'test.txt' with the file you want to include.
eelix
Also, just curious about the '$text' portion of the code on the page - do I need to reference it in the URL and how would I proceed if I wanted to import more than one file?
Thanks so much!
To use multiple gets in the url, you do the following:
[yoursite.com?var1=monkey&var2=fish&var3=cheese...]
//the following prints all $_GET variables
print_r($_GET);
eelix
<?php
$text = @file_get_contents("http://dev.example.com/test$_GET['file_name']") or die("File not found!")
?>
The test page I am using is located at <snip> and the text file itself is located at <snip> - I think partly I am confused about how to write the code and how to add the variable phrase to the URL...especially if the URL already contains other variables (as in the case below). Also, if I wanted to have a few different text files (or image files), how would the code change for each on the page and how would the variables for them differ in the URL?
I also previously tested how to pass two variables and change the Title Tag in the URL while also importing a fixed filed into the page (not controllable via the URL). You can see a sample of that page (with all the variables in the URL) here: [dev.example.com...]
[edited by: jatar_k at 3:26 pm (utc) on May 15, 2006]
[edit reason] no urls thanks [/edit]
<?php
$text = @file_get_contents("http://yoursite.com/test$_GET['file_name']") or die("File not found!")
?>
to
<?php
$text = @file_get_contents("http://yoursite.com/test/".$_GET['file_name']) or die("File not found!");
?>
To see if that changes your whitespace error. Make sure you have a semi-colon at the end of this line
To use multiple variables you would do something like this:
[yousite.com...]
Good luck!
BTW...no personal links on the forum.
eelix
I am trying to insert text (a table) from a file into a page (without the images). Like using the GET function for an image. Instead of using multiple pages with the GET function I can use one page and the image is placed into that page. I want the same option (effect).
I guess I'm trying to insert a table only that is located on another page I wil call table.php. I want the contents form table.php inserted into table2.php. Table2.php will have all the images etc.
Is this all possible?
Thanks.
I'm not quite sure what you mean by this. If you only want to add the contents from table.php into table2.php, then you have to use the include() [us3.php.net] function. If this isn't the case, then can you please clearly specify your needs in other words.
eelix
Code on the Page:
<?php
$text1 = @file_get_contents("http://www.mysite.com/mydirectory/".$_GET['text1']) or die("File not found!");
print "$text1";
?>
Note 1: I added the last line (print "$text1";) and that made a huge difference.
Note 2: In the original code you provided you had $_GET['file_name'] but I changed 'file_name' to 'text1' - and made sure that it was used in the other two spots in the code (basically all of those elements were the same).
Note 3: I tried a version where I called two different text files on the same page, but used 'text2' for the second call and it worked! :)
URL to Access the Page:
[mysite.com...]
eelix