Example #1
0
	/**
	 * Set the filename of this file manually.
	 * Useful for operating on a file after construction.
	 *
	 * @param $filename string
	 */
	public function setFilename($filename) {

		// If this file already has a filename, ensure that it's deleted from cache!
		if($this->_filename){
			Filestore\Factory::RemoveFromCache($this);
		}

		//$cwd = ftp_pwd($this->_ftp->conn);
		$cwd = $this->_ftp->root;

		if(strpos($filename, ROOT_PDIR) === 0){
			// If the file starts with the PDIR... trim that off!
			$filename = substr($filename, strlen(ROOT_PDIR));
			$prefix = ROOT_PDIR;
		}
		elseif(strpos($filename, $cwd) === 0){
			// If the file already starts with the CWD... trim that off!
			$filename = substr($filename, strlen($cwd));
			$prefix = $cwd;
		}
		else{
			$prefix = $cwd;
		}

		// Make sure that prefix ends with a '/'.
		if(substr($prefix, -1) != '/') $prefix .= '/';

		// Resolve if this is an asset, public, etc.
		// This is to speed up the other functions so they don't have to perform this operation.
		if(strpos($prefix . $filename, Filestore\get_asset_path()) === 0){
			$this->_type = 'asset';
		}
		elseif(strpos($prefix . $filename, Filestore\get_public_path()) === 0){
			$this->_type = 'public';
		}
		elseif(strpos($prefix . $filename, Filestore\get_private_path()) === 0){
			$this->_type = 'private';
		}

		$this->_filename = $filename;
		$this->_prefix = $prefix;
		// Clear the local cache too
		$this->_tmplocal = null;
	}
Example #2
0
	/**
	 * Set the filename of this file manually.
	 * Useful for operating on a file after construction.
	 *
	 * @param $filename string
	 */
	public function setFilename($filename) {
		// If this file already has a filename, ensure that it's deleted from cache!
		if($this->_filename){
			Factory::RemoveFromCache($this);
			$this->_filenamecache = [];
		}

		if ($filename{0} != '/') $filename = ROOT_PDIR . $filename; // Needs to be fully resolved

		// Do some cleaning on the filename, ie: // should be just /.
		$filename = str_replace('//', '/', $filename);
		//$filename = preg_replace(':/+:', '/', $filename);

		$this->_filename = $filename;

		// Resolve if this is an asset, public, etc.
		// This is to speed up the other functions so they don't have to perform this operation.
		if(strpos($this->_filename, Filestore\get_asset_path()) === 0){
			$this->_type = 'asset';
		}
		elseif(strpos($this->_filename, Filestore\get_public_path()) === 0){
			$this->_type = 'public';
		}
		elseif(strpos($this->_filename, Filestore\get_private_path()) === 0){
			$this->_type = 'private';
		}
		elseif(strpos($this->_filename, Filestore\get_tmp_path()) === 0){
			$this->_type = 'tmp';
		}
	}