Beispiel #1
0
	/**
	 * Get the temporary local version of the file.
	 * This is useful for doing operations such as hash and identicalto.
	 *
	 * @return FileLocal
	 */
	private function _getTmpLocal() {
		if ($this->_tmplocal === null) {
			// If this FTP object is simply a proxy for the local file store, I can cheat and not actually request the files over FTP.
			// This makes it quicker.
			if($this->_ftp->isLocal){
				$this->_tmplocal = new FileLocal(ROOT_PDIR . $this->_filename);
			}
			else{
				$filename = $this->getFilename();
				$fhash = md5($filename);

				$this->_tmplocal = Filestore\Factory::File('tmp/remotefile-cache/' . $fhash);

				if(!$this->_tmplocal->exists()){
					ftp_get($this->_ftp->getConn(), $this->_tmplocal->getFilename(), $filename, FTP_BINARY);
				}

				// Since I have a local copy, I might as well make sure that the cache is as updated as possible.
				if(!$this->_ftp->getFileHash($filename)){
					$this->_ftp->setFileHash($filename, $this->_tmplocal->getHash());
				}
				if(!$this->_ftp->getFileModified($filename)){
					$this->_ftp->setFileModified($filename, ftp_mdtm($this->_ftp->getConn(), $filename));
				}
				if(!$this->_ftp->getFileSize($filename)){
					$this->_ftp->setFileSize($filename, ftp_size($this->_ftp->getConn(), $filename));
				}
			}
		}
		return $this->_tmplocal;
	}