Jump to content


Photo

Strange file read problem


  • Please log in to reply
2 replies to this topic

#1 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 16 October 2006 - 12:04 PM

i cant see whats wrong with this?? (Warning: fread(): Length parameter must be greater than 0. in c:\program files\easyphp1-8\www\fileeditor\edit.php on line 19)
<?

	// Get the file
	$file = $_GET['file'];
	
	// Check if file is empty
	if (empty($file)) {
		echo "Please Enter A File Name";
		exit();
	}
	
	// Open the file for writing
	if(!($file_handle = fopen($file,"r"))) {
		echo "Cannot Read File";
		exit();
	}
	
	// Read the contents of the file
	$file_contents = fread($file_handle,filesize($file));
	
	// Display The File
	// In a form
?>

http://thewebsolutionprovider.com - A Solution For Everything Web!

#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 16 October 2006 - 12:06 PM

Should work if the file exists. You can use file_exists to check that.

#3 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 16 October 2006 - 12:07 PM

No worries the file being inputted into the script for some reason didnt save more than 0bytes...wierd
http://thewebsolutionprovider.com - A Solution For Everything Web!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users