Jump to content


Photo

Reading a large text file


  • Please log in to reply
1 reply to this topic

#1 benjrox

benjrox
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationSydney, Australia

Posted 23 August 2006 - 06:56 AM

Hi, I have a script that phases a chat log from a IM program to HTML, but when the chat log is bigger then 100KB (I think) it doesn't display a thing. Anything lower works perfectly.
Here's the code:
PHP:
$pext = getFileExtension($log_name);
	$pext = strtolower($pext);
	
	if ($pext != "txr") {
		unlink($log);
		die("Bad file type, please upload a Log file (.txr only).");
	} else {
	        $handle = fopen($log, "r");
			$contents = '';
			if($handle) {
			while (!feof($handle)) {
				$contents .= fread($handle, filesize($log));
				}
				echo fix($contents);
				fclose($handle);
			}
	}
Upload HTML:
<form method="post" enctype="multipart/form-data" action="<? echo $PHP_SELF ?>">
  Log file (.txr):
  <input type="file" name="log" size="30" />
  <input type="hidden" name="action" value="1">
  <br />
  <br />
  <input type="submit" value="View Log">
</form>
Thanks,
Benj

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 23 August 2006 - 08:42 AM

Have you tried just dumping the contents of the file into a variable with file_get_contents() ?
I can't see why it should fail on files over 100k - How long is it taking to execute?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users