Jump to content

fopen error failed to open stream


maxmmize

Recommended Posts

I have an error in my script. I use fopen in a Joomla installation (It's a component)to open a directory containing the header and footer of an external Moodle installation. I basically bridged Moodle and Joomla. This script works correctly in Joomla 1.5 but in 1.0x I get the failed fopen. The error is on 2885 and 2914. The path is manually set inside the configuration of my program and this script should pull that path and perform the operation. This is not happening in 1.0 The lines in question are bolded. I have attached the file to make it easier. Thanks for any help.

 

The errors are:

$file_handle = fopen($path , 'r');

 

and

 

$footer_handle = fopen($footer_path , 'r');

 

	$check_moodle="select value from " . $db_name . ".mdl_config where name='theme'";
		//echo "<br> check_moodle  " . $check_moodle;
		//$result_moodle = mysql_query($check_moodle);
		//$count_result = mysql_num_rows($result_moodle);
		$database->setQuery($check_moodle);
		$moodle_data = $database->loadRow();
		$count_result = count($moodle_data);
		//print_r($moodle_data);

		$server_path= $_SERVER['DOCUMENT_ROOT'];
		$theme_value = $moodle_data[0];
		$path=$server_path . "/moodle/theme/". trim($theme_value) ."/header.html";
		//$path="D:/EasyPHP 2.0b1/www/moodle/theme/standardwhite/header.html";
		  $file_handle = fopen($path , 'r');

		  if ($file_handle) {
			  while(! feof($file_handle))
			  {

				$contents = fgets($file_handle, 4096);
				$find = '<div id="page">';
				$replace = '<div id="page"><?php if (!@$_SESSION["enter"]) { ?>';
				$contents = str_replace($find, $replace, $contents );
				$find2 = '<!-- END OF HEADER -->';
				$replace2 = '<?php } ?><!-- END OF HEADER -->';
				$contents = str_replace($find2, $replace2, $contents );
				@$contents1 .= $contents;
				//echo $contents . "<br />";




			  }
			   fclose($file_handle);
			  //echo $contents1 . "<br />";
			  $file_handle1 = fopen($path , 'w');
				fwrite($file_handle1,$contents1);
				 fclose($file_handle1);

		  }
		 // disabling footer starts here
		 $footer_path=$server_path . "/moodle/theme/". trim($theme_value) ."/footer.html";
		 $footer_handle = fopen($footer_path , 'r');

		  if ($footer_handle) {
			  while(! feof($footer_handle))
			  {

				$footer_contents = fgets($footer_handle, 4096);
				$find = 'echo $loggedinas;';
				$replace = 'if (!@$_SESSION["enter"]) { echo $loggedinas;';
				$footer_contents = str_replace($find, $replace, $footer_contents );
				$find2 = 'echo $homelink;';
				$replace2 = 'echo $homelink; }';
				$footer_contents = str_replace($find2, $replace2, $footer_contents );
				@$footer_contents1 .= $footer_contents;





			  }
			   fclose($footer_handle);
			  
				$footer_handle1 = fopen($footer_path , 'w');
					fwrite($footer_handle1,$footer_contents1);
				fclose($footer_handle1);

		  }





print "<p><font color=green>Moodle Header / Footer are now disabled!</font></p>";

 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.