本文整理汇总了PHP中Base_Common::fileSuffix方法的典型用法代码示例。如果您正苦于以下问题:PHP Base_Common::fileSuffix方法的具体用法?PHP Base_Common::fileSuffix怎么用?PHP Base_Common::fileSuffix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Base_Common
的用法示例。
在下文中一共展示了Base_Common::fileSuffix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
public function upload($path)
{
$this->savePath = $path;
if (!is_dir($this->fileDir . $this->savePath) && !mkdir($this->fileDir . $this->savePath)) {
throw new Base_Exception(sprintf('目录 %s 不存在', $this->fileDir . $this->savePath), 403);
}
@chmod($this->fileDir . $this->savePath);
if (!is_writeable($this->fileDir . $this->savePath)) {
throw new Base_Exception(sprintf('目录 %s 不可写', $this->fileDir . $this->savePath), 403);
}
foreach ($this->fileArr as $k => $file) {
if (!self::isUploadedFile($file['tmp_name'])) {
$this->resultArr[$k]['errno'] = 1;
$this->resultArr[$k]['description'] = '文件上传失败';
continue;
}
$suffix = Base_Common::fileSuffix($file['name']);
$isImage = in_array($suffix, $this->allowImageExtArr);
// if ($this->onlyAllowImage && !$isImage) {
// $this->resultArr[$k]['errno'] = 2;
// $this->resultArr[$k]['description'] = '不允许上传非图片类型文件';
// continue;
// }
if (!in_array($suffix, $this->allowFileExtArr)) {
$this->resultArr[$k]['errno'] = 3;
$this->resultArr[$k]['description'] = '类型文件不允许';
continue;
}
if ($file['size'] > $this->maxFileSize) {
$this->resultArr[$k]['errno'] = 4;
$this->resultArr[$k]['description'] = '文件大小超过限制';
continue;
}
$filename = $file['name'];
$target = $this->fileDir . $this->savePath . '/' . $filename;
$target_root = $this->fileUrl . "/" . $this->savePath . '/' . $filename;
if (move_uploaded_file($file['tmp_name'], $target) || @copy($file['tmp_name'], $target)) {
$this->resultArr[$k]['errno'] = 0;
$this->resultArr[$k]['description'] = '文件上传成功';
$this->resultArr[$k]['path'] = $target;
$this->resultArr[$k]['path_root'] = $target_root;
$this->uploadedFileArr[] = array('name' => $file['name'], 'url' => $this->savePath . $filename, 'type' => $file['type'], 'size' => $file['size'], 'description' => $file['description'], 'is_image' => $isImage);
} else {
$this->resultArr[$k]['errno'] = 5;
$this->resultArr[$k]['description'] = '文件上传失败';
}
}
return $this;
}