本文整理汇总了PHP中wcf\util\FileUtil::formatFilesize方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::formatFilesize方法的具体用法?PHP FileUtil::formatFilesize怎么用?PHP FileUtil::formatFilesize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wcf\util\FileUtil
的用法示例。
在下文中一共展示了FileUtil::formatFilesize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
/**
* Handles uploaded files.
*/
public function upload()
{
// save files
$files = $this->parameters['__files']->getFiles();
$file = $files[0];
try {
if (!$file->getValidationErrorType()) {
$data = array('userID' => WCF::getUser()->userID ?: null, 'filename' => $file->getFilename(), 'fileType' => $file->getMimeType(), 'fileHash' => sha1_file($file->getLocation()), 'filesize' => $file->getFilesize(), 'uploadTime' => TIME_NOW);
// save file
$upload = FileUploadEditor::create($data);
// move uploaded file
if (@copy($file->getLocation(), $upload->getLocation())) {
@unlink($file->getLocation());
// return result
return array('uploadID' => $upload->uploadID, 'filename' => $upload->filename, 'filesize' => $upload->filesize, 'formattedFilesize' => FileUtil::formatFilesize($upload->filesize));
} else {
// moving failed; delete file
$editor = new FileUploadEditor($upload);
$editor->delete();
throw new UserInputException('fileUpload', 'uploadFailed');
}
}
} catch (UserInputException $e) {
$file->setValidationErrorType($e->getType());
}
return array('errorType' => $file->getValidationErrorType());
}
示例2: upload
/**
* Handles uploaded files.
*/
public function upload()
{
// save files
$files = $this->parameters['__files']->getFiles();
$file = $files[0];
try {
if (!$file->getValidationErrorType()) {
$data = array('title' => $file->getFilename(), 'fileExtension' => $file->getFileExtension(), 'fileType' => $file->getMimeType(), 'fileHash' => sha1_file($file->getLocation()), 'filesize' => $file->getFilesize(), 'uploadTime' => TIME_NOW);
// save file
$picture = NewsPictureEditor::create($data);
// move uploaded file
if (@copy($file->getLocation(), $picture->getLocation())) {
@unlink($file->getLocation());
// return result
return array('pictureID' => $picture->pictureID, 'title' => $picture->title, 'filesize' => $picture->filesize, 'formattedFilesize' => FileUtil::formatFilesize($picture->filesize), 'url' => $picture->getURL());
} else {
// moving failed; delete file
$editor = new NewsPictureEditor($picture);
$editor->delete();
throw new UserInputException('picture', 'uploadFailed');
}
}
} catch (UserInputException $e) {
$file->setValidationErrorType($e->getType());
}
return array('errorType' => $file->getValidationErrorType());
}
示例3: getMemoryUsage
/**
* Returns the formatted peak of memory_usage.
*
* @return string
*/
public function getMemoryUsage()
{
return FileUtil::formatFilesize(memory_get_peak_usage());
}
示例4: execute
/**
* @see wcf\system\template\IModifierTemplatePlugin::execute()
*/
public function execute($tagArgs, TemplateEngine $tplObj) {
return FileUtil::formatFilesize($tagArgs[0]);
}
示例5: upload
//.........这里部分代码省略.........
}
}
// create attachment
$attachment = AttachmentEditor::create($data);
// check attachment directory
// and create subdirectory if necessary
$dir = dirname($attachment->getLocation());
if (!@file_exists($dir)) {
FileUtil::makePath($dir, 0777);
}
// move uploaded file
if (@move_uploaded_file($file->getLocation(), $attachment->getLocation())) {
if ($attachment->isImage) {
$thumbnails[] = $attachment;
// rotate image based on the exif data
$neededMemory = $attachment->width * $attachment->height * ($attachment->fileType == 'image/png' ? 4 : 3) * 2.1;
if (FileUtil::getMemoryLimit() == -1 || FileUtil::getMemoryLimit() > memory_get_usage() + $neededMemory) {
$exifData = ExifUtil::getExifData($attachment->getLocation());
if (!empty($exifData)) {
$orientation = ExifUtil::getOrientation($exifData);
if ($orientation != ExifUtil::ORIENTATION_ORIGINAL) {
$adapter = ImageHandler::getInstance()->getAdapter();
$adapter->loadFile($attachment->getLocation());
$newImage = null;
switch ($orientation) {
case ExifUtil::ORIENTATION_180_ROTATE:
$newImage = $adapter->rotate(180);
break;
case ExifUtil::ORIENTATION_90_ROTATE:
$newImage = $adapter->rotate(90);
break;
case ExifUtil::ORIENTATION_270_ROTATE:
$newImage = $adapter->rotate(270);
break;
case ExifUtil::ORIENTATION_HORIZONTAL_FLIP:
case ExifUtil::ORIENTATION_VERTICAL_FLIP:
case ExifUtil::ORIENTATION_VERTICAL_FLIP_270_ROTATE:
case ExifUtil::ORIENTATION_HORIZONTAL_FLIP_270_ROTATE:
// unsupported
break;
}
if ($newImage !== null) {
$adapter->load($newImage, $adapter->getType());
}
$adapter->writeImage($attachment->getLocation());
if ($newImage !== null) {
// update width, height and filesize of the attachment
if ($orientation == ExifUtil::ORIENTATION_90_ROTATE || $orientation == ExifUtil::ORIENTATION_270_ROTATE) {
$attachmentEditor = new AttachmentEditor($attachment);
$attachmentEditor->update(array('height' => $attachment->width, 'width' => $attachment->height, 'filesize' => filesize($attachment->getLocation())));
}
}
}
}
}
} else {
// check whether we can create thumbnails for this file
$this->eventAttachment = $attachment;
$this->eventData = array('hasThumbnail' => false);
EventHandler::getInstance()->fireAction($this, 'checkThumbnail');
if ($this->eventData['hasThumbnail']) {
$thumbnails[] = $attachment;
}
}
$attachments[$file->getInternalFileID()] = $attachment;
} else {
// moving failed; delete attachment
$editor = new AttachmentEditor($attachment);
$editor->delete();
}
}
// generate thumbnails
if (ATTACHMENT_ENABLE_THUMBNAILS) {
if (!empty($thumbnails)) {
$action = new AttachmentAction($thumbnails, 'generateThumbnails');
$action->executeAction();
}
}
// return result
$result = array('attachments' => array(), 'errors' => array());
if (!empty($attachments)) {
// get attachment ids
$attachmentIDs = $attachmentToFileID = array();
foreach ($attachments as $internalFileID => $attachment) {
$attachmentIDs[] = $attachment->attachmentID;
$attachmentToFileID[$attachment->attachmentID] = $internalFileID;
}
// get attachments from database (check thumbnail status)
$attachmentList = new AttachmentList();
$attachmentList->getConditionBuilder()->add('attachment.attachmentID IN (?)', array($attachmentIDs));
$attachmentList->readObjects();
foreach ($attachmentList as $attachment) {
$result['attachments'][$attachmentToFileID[$attachment->attachmentID]] = array('filename' => $attachment->filename, 'filesize' => $attachment->filesize, 'formattedFilesize' => FileUtil::formatFilesize($attachment->filesize), 'isImage' => $attachment->isImage, 'attachmentID' => $attachment->attachmentID, 'tinyURL' => $attachment->tinyThumbnailType ? LinkHandler::getInstance()->getLink('Attachment', array('object' => $attachment), 'tiny=1') : '', 'thumbnailURL' => $attachment->thumbnailType ? LinkHandler::getInstance()->getLink('Attachment', array('object' => $attachment), 'thumbnail=1') : '', 'url' => LinkHandler::getInstance()->getLink('Attachment', array('object' => $attachment)), 'height' => $attachment->height, 'width' => $attachment->width);
}
}
foreach ($failedUploads as $failedUpload) {
$result['errors'][$failedUpload->getInternalFileID()] = array('filename' => $failedUpload->getFilename(), 'filesize' => $failedUpload->getFilesize(), 'errorType' => $failedUpload->getValidationErrorType());
}
return $result;
}
示例6: upload
/**
* 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;
}