Exemplo n.º 1
0
	/**
	 * Copy a file to a destination.
	 *
	 * After executing this method successfully, this object will not point to the new file!
	 * If the specified destination does not exist this function returns false.
	 *
	 * This function implements the ftp fallback!
	 *
	 * @param string Destination path
	 * @return bool Returns true on success, false on failure
	 */
	public function copy($dest) {
		if ($this->exists() == false) {
			return false;
		}

		if (copy($this->path, $dest) == true) {
			return true;
		}
		elseif ($this->ftp == true) {
			$fp = fopen($this->path, "r");
			$ftp = FileSystem::initializeFTP();
			if (is_resource($fp) == true && $ftp !== null) {
				$ret = $ftp->put($fp, $this->ftpizePath($dest));
				fclose($fp);
				return $ret;
			}
		}
		return false;
	}
	/**
	 * Attempts to move the file/folder to the specified path.
	 *
	 * After executing this method successfully, this object will point to the new file/folder!
	 * To just rename a file/folder please consider using the FileSystemNode::rename() function.
	 * If there is already a file/folder with the name specified as parameter nothing will be done
	 * and false will be returned.
	 *
	 * This function implements the ftp fallback!
	 *
	 * @see Folder::rename()
	 * @see File::rename()
	 * @param string Path to the new location.
	 * @return boolean Returns TRUE on success or FALSE on failure.
	 */
	public function move($dest) {
		if ($this->exists() == false || file_exists($dest) == true) {
			return false;
		}

		if (rename($this->path, $dest) == true) {
			$this->path = $dest;
			return true;
		}
		elseif ($this->ftp == true) {
			$ftp = FileSystem::initializeFTP();
			if ($ftp !== null && $ftp->rename($this->ftpPath(), $this->ftpize($dest)) === true) {
				$this->path = $dest;
				return true;
			}
		}
		return false;
	}
	/**
	 * Deletes the folder completely with all contents.
	 *
	 * Does nothing when the folder does not exist and returns true.
	 *
	 * This function implements the ftp fallback!
	 *
	 * @return boolean Returns TRUE on success or FALSE on failure.
	 */
	public function delete() {
		if ($this->exists() == false) {
			return true;
		}

		// Remove the content
		$clear = $this->clear();
		if ($clear == true && rmdir($this->path) == true) {
			return true;
		}
		elseif ($clear == true && $this->ftp == true) {
			$ftp = FileSystem::initializeFTP();
			if ($ftp !== null) {
				return $ftp->rmdir($this->ftpPath());
			}
		}
		return false;
	}