Hi, the code section below is a function out of a class i am currently working which is an API so i dont fully know the server setup it will run on but do want to offer caching so am using few checks.

Anyway... my issue is with creating a text file, my understanding of the directory setup is that . means your current directory, when running this script on a server without memcache i am getting the error "could not create a cache text file" which is from fopen yet my if function before this checks if the folder is writeable, and also the /cache/ folder is created and has 0775 permissions does fopen allow ./cache/blah.txt ??

Thanks in advance
P.S $this->debug is set to TRUE at the time of running the script, so i can see the errors

		
		private function write_cache($information, $username){
			if(class_exists("Memcache")){//if memcache is installed
				//write memcache cache bit
			}else{
				if(is_writable('.')){//if we can write to the current directory
					if(!is_dir('./cache')){//is there a cache folder
						$status = @mkdir('./cache', 0775);//make cache folder

					if(!$status){//creation of cache folder failed ?
						if($this->debug){
							throw new Exception('Could not create ./cache/ folder');
						}
					}	
				}

				if(is_writable('./cache/')){//if we can write to the cache directory
					$file = @fopen('./cache/'.md5($username).'.txt', 'r') or die('could not create a cache text file');

					if($file){
						$tmp = array('data', 'timestamp');
						$tmp['data'] 		= $information;
						$tmp['timestamp'] 	= (time()+$this->cache_time); 

						@fwrite($file, serialize($tmp));
						@fclose($file);
					}else{
						if($this->debug){
							throw new Exception('could not create a cache text file');
						}
					}
				}else{
					if($this->debug){
						throw new Exception('/cache/ directory is not writeable');
					}
				}
			}else{
				if($this->debug){
					throw new Exception('current directory isnt writeable..no chance of cache folder');
				}
			}
		}
	}

    oh sorry about this just noticed i have R instead of W within fopen

      Write a Reply...