/** * @see \wcf\page\IPage::readData() */ public function readData() { parent::readData(); VisitCountHandler::getInstance()->count(); $this->fileReader = new FileReader($this->file->getLocation(), array('filename' => $this->file->getTitle(), 'mimeType' => $this->file->fileType, 'filesize' => $this->file->filesize, 'showInline' => in_array($this->file->fileType, self::$inlineMimeTypes), 'enableRangeSupport' => false, 'lastModificationTime' => $this->file->uploadTime, 'expirationDate' => TIME_NOW + 31536000, 'maxAge' => 31536000)); // count downloads $fileEditor = new FileEditor($this->file); $fileEditor->updateCounters(array('downloads' => 1)); }
/** * @see \wcf\data\IEditableObject::deleteAll() */ public static function deleteAll(array $objectIDs = array()) { $fileList = new FileList(); $fileList->setObjectIDs($objectIDs); $fileList->readObjects(); foreach ($fileList as $object) { $fileEditor = new FileEditor($object); $fileEditor->deleteFile(); } return parent::deleteAll($objectIDs); }
/** * Handles upload of a file. */ public function upload() { $files = $this->parameters['__files']->getFiles(); $failedUploads = array(); $result = array('files' => array(), 'errors' => array()); foreach ($files as $file) { try { if ($file->getValidationErrorType()) { $failedUploads[] = $file; continue; } $data = array('title' => $file->getFilename(), 'filesize' => $file->getFilesize(), 'fileType' => $file->getMimeType(), 'fileHash' => sha1_file($file->getLocation()), 'uploadTime' => TIME_NOW); $uploadedFile = FileEditor::create($data); //clear cache FileCacheBuilder::getInstance()->reset(); // create subdirectory if necessary $dir = dirname($uploadedFile->getLocation()); if (!@file_exists($dir)) { FileUtil::makePath($dir, 0777); } // move uploaded file if (@move_uploaded_file($file->getLocation(), $uploadedFile->getLocation())) { @unlink($file->getLocation()); $result['files'][$file->getInternalFileID()] = array('fileID' => $uploadedFile->fileID, 'title' => $uploadedFile->getTitle(), 'filesize' => $uploadedFile->filesize, 'formattedFilesize' => FileUtil::formatFilesize($uploadedFile->filesize)); } else { // failure $editor = new FileEditor($uploadedFile); $editor->delete(); throw new UserInputException('file', 'uploadFailed'); } } catch (UserInputException $e) { $file->setValidationErrorType($e->getType()); $failedUploads[] = $file; } } // return results foreach ($failedUploads as $failedUpload) { $result['errors'][$failedUpload->getInternalFileID()] = array('title' => $failedUpload->getFilename(), 'filesize' => $failedUpload->getFilesize(), 'errorType' => $failedUpload->getValidationErrorType()); } return $result; }