本文整理汇总了PHP中Topxia\Common\FileToolkit::getFileTypeByExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP FileToolkit::getFileTypeByExtension方法的具体用法?PHP FileToolkit::getFileTypeByExtension怎么用?PHP FileToolkit::getFileTypeByExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Topxia\Common\FileToolkit
的用法示例。
在下文中一共展示了FileToolkit::getFileTypeByExtension方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addFile
public function addFile(array $fileInfo = array(), UploadedFile $originalFile = null)
{
$errors = FileToolkit::validateFileExtension($originalFile);
if ($errors) {
@unlink($originalFile->getRealPath());
throw $this->createServiceException("该文件格式,不允许上传。");
}
$uploadFile = array();
$uploadFile['storage'] = 'local';
$uploadFile['filename'] = $originalFile->getClientOriginalName();
$uploadFile['ext'] = FileToolkit::getFileExtension($originalFile);
$uploadFile['size'] = $originalFile->getSize();
$filename = FileToolkit::generateFilename($uploadFile['ext']);
$uploadFile['hashId'] = "course/{$filename}";
$uploadFile['convertHash'] = "ch-{$uploadFile['hashId']}";
$uploadFile['convertStatus'] = 'none';
$uploadFile['type'] = FileToolkit::getFileTypeByExtension($uploadFile['ext']);
$uploadFile['isPublic'] = empty($fileInfo['isPublic']) ? 0 : 1;
$uploadFile['canDownload'] = empty($uploadFile['canDownload']) ? 0 : 1;
$uploadFile['updatedUserId'] = $uploadFile['createdUserId'] = $this->getCurrentUser()->id;
$uploadFile['updatedTime'] = $uploadFile['createdTime'] = time();
$targetPath = $this->getFilePath('course', $uploadFile['isPublic']);
$originalFile->move($targetPath, $filename);
return $uploadFile;
}
示例2: addFile
public function addFile($targetType, $targetId, array $fileInfo = array(), UploadedFile $originalFile = null)
{
if (!ArrayToolkit::requireds($fileInfo, array('filename', 'key', 'size'))) {
throw $this->createServiceException('参数缺失,添加用户文件失败!');
}
$uploadFile = array();
$uploadFile['targetId'] = $targetId;
$uploadFile['targetType'] = $targetType;
$uploadFile['hashId'] = $fileInfo['key'];
$uploadFile['filename'] = $fileInfo['filename'];
$uploadFile['ext'] = pathinfo($uploadFile['filename'], PATHINFO_EXTENSION);
$uploadFile['size'] = (int) $fileInfo['size'];
$uploadFile['etag'] = empty($fileInfo['etag']) ? '' : $fileInfo['etag'];
$uploadFile['length'] = empty($fileInfo['length']) ? 0 : intval($fileInfo['length']);
$uploadFile['metas'] = $this->encodeMetas(empty($fileInfo['metas']) ? array() : $fileInfo['metas']);
$uploadFile['metas2'] = $this->encodeMetas(empty($fileInfo['metas2']) ? array() : $fileInfo['metas2']);
if ($fileInfo['lazyConvert']) {
$fileInfo['convertHash'] = "lazy-{$uploadFile['hashId']}";
}
if (empty($fileInfo['convertHash'])) {
$uploadFile['convertHash'] = "ch-{$uploadFile['hashId']}";
$uploadFile['convertStatus'] = 'none';
$uploadFile['convertParams'] = '';
} else {
if ('document' == FileToolkit::getFileTypeByExtension($uploadFile['ext'])) {
$uploadFile['convertHash'] = "{$fileInfo['convertHash']}";
$uploadFile['convertStatus'] = 'none';
$uploadFile['convertParams'] = $fileInfo['convertParams'];
} else {
$uploadFile['convertHash'] = "{$fileInfo['convertHash']}";
$uploadFile['convertStatus'] = 'waiting';
$uploadFile['convertParams'] = $fileInfo['convertParams'];
}
}
$uploadFile['type'] = FileToolkit::getFileTypeByExtension($uploadFile['ext']);
$uploadFile['canDownload'] = empty($uploadFile['canDownload']) ? 0 : 1;
$uploadFile['storage'] = 'cloud';
$uploadFile['createdUserId'] = $this->getCurrentUser()->id;
$uploadFile['updatedUserId'] = $uploadFile['createdUserId'];
$uploadFile['updatedTime'] = $uploadFile['createdTime'] = time();
return $uploadFile;
}
示例3: addFile
public function addFile($targetType, $targetId, array $fileInfo = array(), UploadedFile $originalFile = null)
{
$errors = FileToolkit::validateFileExtension($originalFile);
if ($errors) {
@unlink($originalFile->getRealPath());
throw $this->createServiceException("该文件格式,不允许上传。");
}
$uploadFile = array();
$time = time();
$uploadFile['storage'] = 'local';
$uploadFile['targetId'] = $targetId;
$uploadFile['targetType'] = $targetType;
$uploadFile['filename'] = $originalFile->getClientOriginalName();
//$uploadFile['filename'] = $time.$uploadFile['filename'];
$uploadFile['ext'] = FileToolkit::getFileExtension($originalFile);
$uploadFile['size'] = $originalFile->getSize();
$filename = FileToolkit::generateFilename($uploadFile['ext']);
$uploadFile['hashId'] = "{$uploadFile['targetType']}/{$uploadFile['targetId']}/{$filename}";
$uploadFile['convertHash'] = "ch-{$uploadFile['hashId']}";
$uploadFile['convertStatus'] = 'none';
$uploadFile['type'] = FileToolkit::getFileTypeByExtension($uploadFile['ext']);
$uploadFile['isPublic'] = empty($fileInfo['isPublic']) ? 0 : 1;
$uploadFile['canDownload'] = empty($uploadFile['canDownload']) ? 0 : 1;
$uploadFile['updatedUserId'] = $uploadFile['createdUserId'] = $this->getCurrentUser()->id;
$uploadFile['updatedTime'] = $uploadFile['createdTime'] = time();
//$uploadFile['filePath'] = $this->getFilePath();
//throw new \RuntimeException(print_r('ssd'));
//throw $this->createServiceException(print_r('ssd'));
//$key = $uploadFile['filename'];
//qiniu();
//转存上传临时文件到资源文件夹(由于业务服务器硬盘较小,故不作备份,直接上传到七牛云。如需开启则删除下面注释符) 以下代码未包含删备份
$targetPath = $this->getFilePath($targetType, $targetId, $uploadFile['isPublic']);
$originalFile->move($targetPath, $filename);
//todo 上传到七牛处理代码(存储、转码、拼接、水印)20151224
//$config = $this->getQiniuService()->initQiniu($targetPath,$filename);
return $uploadFile;
}