# PHP unlink



## pcpro17 (Oct 9, 2006)

Hello. Does anyone know what this warning message means?

Warning: unlink() [function.unlink]: Unable to locate stream wrapper in /home/.printout/therealhopeful/correctnesscommentary.com/wp/wp-content/themes/earth/lastRSS.php on line 9

Here is a bit of my code that may be causing this error. This code is meant as a "patch" to get some other code (LastRSS) downloaded off the Internet working because the LastRSS get function won't working on my hosting service. (They've dissallowed fopen.):

```
class downloader {
    var $tempFolder = temp_dir;
    var $tempFiles = array();
    var $fp;

    function __destruct () {
        foreach ($this->tempFiles as $file) {
            unlink($file['temp']);
        }
    }
    
    function __construct ($temp)
    {
        $this->tempFolder = $temp;
    }
    
    function get ($url) {
        array_unshift($this->tempFiles, array(
            'extension'=> array_pop(explode('.', $url)),
            'original'=> basename($url),
            'temp'=> $this->tempFolder . md5(microtime()),
        ));
        $ch = curl_init($url);
        $fp = fopen($this->tempFiles[0]['temp'], 'w');
/*
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_exec($ch);
        curl_close($ch);
        fclose($fp);
        return $this->tempFiles[0]['temp'];
*/
        return $fp;
    }
    
    function read ($index = 0) {
        return file_get_contents($this->tempFiles[$index]['temp']);
    }
    
    function readArray ($index = 0)
    {
        return file($this->tempFiles[$index]['temp']);
    }
    
    function listFiles () {
        return $this->tempFiles;
    }
    
    function save ($path, $index = 0) {
        copy($this->tempFiles[$index]['temp'], (is_dir($path) ? 
            $path . $this->tempFiles[$index]['original'] : 
            $path));
    }
}
```
Here's the LastRSS Get function that I'm trying to modify to use the above:

```
// -------------------------------------------------------------------
	// Parse RSS file and returns associative array.
	// -------------------------------------------------------------------
	function Get ($rss_url) {
		$d = new downloader($rss_url);
		// If CACHE ENABLED
		if ($this->cache_dir != '') {
			$cache_file = $this->cache_dir . '/rsscache_' . md5($rss_url);
			$timedif = @(time() - filemtime($cache_file));
			if ($timedif < $this->cache_time) {
				// cached file is fresh enough, return cached array
				$result = unserialize(join('', file($cache_file)));
				// set 'cached' to 1 only if cached file is correct
				if ($result) $result['cached'] = 1;
			} else {
				// cached file is too old, create new
				$result = $this->Parse($rss_url);
				$serialized = serialize($result);
/*
				if ($f = @fopen($cache_file, 'w')) {
					fwrite ($f, $serialized, strlen($serialized));
					fclose($f);
				}
*/
				if ($f = @$d->get($rss_url)) {
					fwrite ($f, $serialized, strlen($serialized));
					fclose($f);
				}
//				$f = @$d->get($rss_url);
				if ($result) $result['cached'] = 0;
			}
		}
		// If CACHE DISABLED >> load and parse the file directly
		else {
			$result = $this->Parse($rss_url);
			if ($result) $result['cached'] = 0;
		}
		// return result
		return $result;
	}
```
Any thoughts or suggestions would be greatly appreciated, as I'm pretty much stuck on this one.


----------



## Big-K (Nov 22, 2003)

i'm not sure what the message means, but you might want to change unlink($file['temp']); to if(file_exists($file['temp'])){ unlink($file['temp']); }, that way it only tries to delete it if the file exists, so you don't get an error message when the file doesn't exist.


----------

