Jump to content

[SOLVED] continue output after fopen() error?


Dragen

Recommended Posts

Hi,

I've got this script which opens a txt file, taking the directory from variables.

<?php
			$file = "downloads/" . $category . "_" . $item . ".txt"; // opens the txt file for the item. Then sets description as the text file.
			$fh = fopen($file, 'r') or die("Error: Can't find description");
			$description = fread($fh, filesize($file)); // no need for addslashes as data is read as html not php
			fclose($fh);
			echo $description; 
?>

 

If it can't open the file it brings up the error:

Warning: fopen(downloads/games_romasantah.txt): failed to open stream: No such file or directory in /home/fhlinux181/g/gimppro.co.uk/user/htdocs/dwnviewitm.php on line 44
Error: Can't find description

outputting the warning then my error message, which is fine.

The problem is, because I'm using or die(), it doesn't output any of my code past the open file section, meaning that anything else I wish to display below is not shown.

If I remove the or die, it brings up the same error and several more, because it can't find the other variables etc.

 

Is there a way I can write this so that it simply displays the error, but continues after the 'fclose();'?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/47866-solved-continue-output-after-fopen-error/
Share on other sites

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.