/** * Process the upload and update the value of this field * @return null */ public function processRequest() { if (!isset($_FILES[$this->name])) { $this->setValue($this->getDefaultValue()); return; } $this->uploadPath->create(); if (!$this->uploadPath->isWritable()) { throw new ZiboException('Upload path ' . $this->uploadPath->getAbsolutePath() . ' is not writable'); } if (!$this->isMultiple()) { $formFile = $this->uploadFile($_FILES[$this->name]); $this->setValue($formFile); return; } $values = array(); $files = $this->getMultipleFiles($_FILES[$this->name]); foreach ($files as $file) { if ($file['error'] == UPLOAD_ERR_NO_FILE) { continue; } $formFile = $this->uploadFile($file); $values[] = $formFile; } $this->setValue($values); }
/** * Finished the installation, remove the installation module and redirect * @return null */ public function finish() { $installModule = new File(__DIR__ . '/../../../../'); $installModule->delete(); $installScript = new File($installModule->getParent()->getParent(), 'install.php'); if ($installScript->exists() && $installScript->isWritable()) { $installScript->delete(); } $zibo = Zibo::getInstance(); $request = $zibo->getRequest(); $response = $zibo->getResponse(); $response->setRedirect($request->getBaseUrl()); }
/** * Constructs a new repository * @param zibo\library\filesystem\File $directory The directory of the repository * @return null * @throws zibo\ZiboException when the provided directory does not exist or when it's not writable */ public function __construct(File $directory) { $directory->create(); if (!$directory->isDirectory()) { throw new ZiboException($directory->getAbsolutePath() . ' is not a directory'); } if (!$directory->isWritable()) { throw new ZiboException($directory->getAbsolutePath() . ' is not writable'); } $this->directory = $directory; $this->isIndexDirty = false; $this->readIndexFile(); }
/** * Checks if the application directory exists and is writable * @return null */ public function performCheck() { $root = Zibo::getInstance()->getRootPath(); $directory = new File($root, $this->path); $this->isMet = false; if (!$directory->exists()) { try { $directory->create(); } catch (ZiboException $exception) { $this->message = $this->messageExists; return; } } if ($this->messageWritable && !$directory->isWritable()) { $this->message = $this->messageWritable; return; } $this->isMet = true; }
/** * Downloads a file from the FTP server * @param string $remoteFile The source file on the FTP server * @param zibo\library\filesystem\File $localFile The destination to save the source in * @param integer $mode ASCII or binary (constants FTP_ASCII or FTP_BINARY) * @return null * @throws zibo\library\ftp\exception\FtpException when not connected to the FTP server * @throws zibo\library\ftp\exception\FtpException when the file could not be downloaded */ public function get($remoteFile, File $localFile, $mode = null) { $this->checkConnected(); if ($localFile->exists() && $localFile->isDirectory()) { throw new FtpException('Could not download ' . $remoteFile . ': Destination ' . $localFile . ' is a directory'); } elseif (!$localFile->isWritable()) { throw new FtpException('Could not download ' . $remoteFile . ': Destination ' . $localFile . ' is a not writable'); } if (!$mode) { $mode = FTP_BINARY; } if (!@ftp_get($this->handle, $localFile->getPath(), $remoteFile, $mode)) { throw new FtpException('Could not download ' . $remoteFile . ': A problem occured while downloading'); } }
/** * Action to process files and directories from the clipboard to the current path * @param string $action The method to invoke (copy or move) * @param array $files Array with the files to copy * @return null */ private function clipboardFileAction($action, array $files = null) { $this->response->setRedirect($this->getReferer()); if ($files == null) { return; } $root = $this->fileBrowser->getRoot(); $baseDestination = new File($root, $this->path); foreach ($files as $file) { $file = new File($file); $path = $file->getPath(); if (!array_key_exists($path, $this->clipboard)) { continue; } $source = new File($root, $file); $destination = new File($baseDestination, $file->getName()); if (!$destination->isWritable()) { $this->addError(self::TRANSLATION_ERROR_WRITABLE, array('path' => $this->fileBrowser->getPath($destination))); continue; } $source->{$action}($destination); unset($this->clipboard[$path]); } }