|
-
Apr 25th, 2005, 04:21 PM
#1
Thread Starter
Hyperactive Member
Resource id #2
hi, i have made this code that reads a text doc and echos it to the page. here is my code:
PHP Code:
<?
$user = $_GET['user'];
echo '<html>
<head>
<title>Dans Web Server 2005!</title>
</head>
<body>
<h1>';
echo fopen($user . "fn.txt","r");
echo '</h1>
</body>
</html>'
?>
it is ment to echo what is in a text file (username and "fn.txt") but insted it echos Resource id #2. what is wrong with my code?
thanks, dandono
If there is only one perfect person in the universe, does that make them imperfect?
-
Apr 27th, 2005, 04:45 AM
#2
Re: Resource id #2
Once you have opened a file with fopen, a resource is returned. The resource holds all the information about the file, like the current position of the pointer, its name, its handle and other things.
So once you have opened your file you must use functions such as fread() and fgets() to read the contents, which all take a file pointer resource as one of their parameters.
In your case, as you want to just dump the entire file, you should use the fpassthru() function.
PHP Code:
<?php
$user = $_GET['user'];
// assign the resource to a variable
if (! $fhwnd = fopen($user . 'fn.txt','r')) {
die('Failed to open file.');
}
?>
<html>
<head>
<title>Dans Web Server 2005!</title>
</head>
<body>
<h1><?php fpassthru($fhwnd) ?></h1>
</body>
</html>
-
Apr 27th, 2005, 02:41 PM
#3
Thread Starter
Hyperactive Member
Re: Resource id #2
how would i be able to do this when opening more than 1 text doc?
If there is only one perfect person in the universe, does that make them imperfect?
-
Apr 27th, 2005, 03:13 PM
#4
Re: Resource id #2
I'm not entirely sure what you mean. But, you can have more than one file open at a time. Just assign each resource to a different varaible. Don't forget to close the file after you have finished with it by using the fclose() function.
-
Apr 28th, 2005, 10:10 AM
#5
Thread Starter
Hyperactive Member
Re: Resource id #2
i ment to echo one files contents and then another files contents and so on
If there is only one perfect person in the universe, does that make them imperfect?
-
Apr 28th, 2005, 10:28 AM
#6
Re: Resource id #2
PHP Code:
<?php
$user = $_GET['user'];
// assign the resource to a variable
if (! $fhwnd1 = fopen($user . 'file1.txt','r')) {
die('Failed to open file 1.');
}
if (! $fhwnd2 = fopen($user . 'file2.txt','r')) {
die('Failed to open file 2.');
}
?>
<html>
<head>
<title>Dans Web Server 2005!</title>
</head>
<body>
<h1><?php fpassthru($fhwnd1) ?></h1>
<h1><?php fpassthru($fhwnd2) ?></h1>
</body>
</html>
-
Apr 28th, 2005, 11:46 AM
#7
Thread Starter
Hyperactive Member
If there is only one perfect person in the universe, does that make them imperfect?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|