/** * Handles a single upload by given CUploadedFile and returns an array * of informations. * * The 'error' attribute of the array, indicates there was an error. * * Informations on error: * - error: true * - errorMessage: some message * - name: name of the file * - size: file size * * Informations on success: * - error: false * - name: name of the uploaded file * - size: file size * - guid: of the file * - url: url to the file * - thumbnailUrl: url to the thumbnail if exists * * @param type $cFile * @return Array Informations about the uploaded file */ protected function handleFileUpload($cFile, $object = null) { $output = array(); $file = new File(); $file->setUploadedFile($cFile); if ($object != null) { $file->object_id = $object->getPrimaryKey(); $file->object_model = $object->className(); } if ($file->validate() && $file->save()) { $output['error'] = false; $output['guid'] = $file->guid; $output['name'] = $file->file_name; $output['title'] = $file->title; $output['size'] = $file->size; $output['mimeIcon'] = \humhub\libs\MimeHelper::getMimeIconClassByExtension($file->getExtension()); $output['mimeBaseType'] = $file->getMimeBaseType(); $output['mimeSubType'] = $file->getMimeSubType(); $output['url'] = $file->getUrl("", false); $output['thumbnailUrl'] = $file->getPreviewImageUrl(200, 200); } else { $output['error'] = true; $output['errors'] = $file->getErrors(); } $output['name'] = $file->file_name; $output['size'] = $file->size; $output['deleteUrl'] = ""; $output['deleteType'] = ""; $output['thumbnailUrl'] = ""; return $output; }
<!-- Show List of all files --> <hr> <ul class="files" style="list-style: none; margin: 0;" id="files-<?php echo $object->getPrimaryKey(); ?> "> <?php foreach ($files as $file) { ?> <?php if ($file->getMimeBaseType() == "image" && $hideImageFileInfo) { continue; } ?> <li class="mime <?php echo \humhub\libs\MimeHelper::getMimeIconClassByExtension($file->getExtension()); ?> "><a href="<?php echo $file->getUrl(); ?> " target="_blank"><span class="filename"><?php echo Html::encode(Helpers::trimText($file->file_name, 40)); ?> </span></a> <span class="time" style="padding-right: 20px;"> - <?php echo Yii::$app->formatter->asShortSize($file->size, $decimals = 1); ?> </span>
public function getInfoArray() { $info = []; $info['error'] = false; $info['guid'] = $this->guid; $info['name'] = $this->file_name; $info['title'] = $this->title; $info['size'] = $this->size; $info['mimeIcon'] = \humhub\libs\MimeHelper::getMimeIconClassByExtension($this->getExtension()); $info['mimeBaseType'] = $this->getMimeBaseType(); $info['mimeSubType'] = $this->getMimeSubType(); $info['url'] = $this->getUrl("", false); $info['thumbnailUrl'] = $this->getPreviewImageUrl(200, 200); return $info; }
echo $uploaderId; ?> " > <ul style="list-style: none; margin: 0;" class="contentForm-upload-list" id="embeddedmediaUploaderListUl_<?php echo $uploaderId; ?> "></ul> </div> <script> <?php foreach ($files as $file) { ?> addToUploadList("<?php echo $uploaderId; ?> ", "<?php echo $file->guid; ?> ", "<?php echo $file->file_name; ?> ", "<?php echo MimeHelper::getMimeIconClassByExtension($file->getExtension()); ?> "); <?php } ?> </script>