Jump to content

Help with fopen()


ThePsion5

Recommended Posts

Hi guys. I'm writing a PHP script that involves creating and then accessing a file. I'm running into a strange problem, however: when I use fopen() to open the file, it succeeds (does not generate any warnings/errors) but instead of returning a file handle, it returns 1/true. Any idea what might be causing this?

if(!file_exists($Filename))		//Create the file handle		$FileHandle = fopen($Filename, 'w');		//If the file could not be opened or created, throw an exception		print_r($FileHandle); //PROBLEM: Prints 1 instead of the file handle		if(!$FileHandle)			throw new Exception('Unable to create or open the following file for writing: "'.$Filename. '" in directory "'.$this->CacheFileLocation.'"');		else		{			//Save the data in the file			fwrite($FileHandle, $Content); //Here i get an error saying that "$FileHandle" is not a valid resource			//Close the file stream handle			fclose($FileHandle);				//Same here		}

Link to comment
Share on other sites

uhm, my personal preferences say use file_get_contents and file_put_contents. Just as a thought on this one. See if those return the same results.

Link to comment
Share on other sites

file_put_contents is only available in PHP5. Also, the documentation for file_put_contents says that is it identical to calling fopen, fwrite, and fclose. This should work, there's no reason why fopen should return boolean true, regardless of what file_put_contents does.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...