当我尝试上传通过Photoshop编辑的图像(任何格式)时,该页面无法正常工作,好像我下载了任何图像然后又上传了图像一样,我不知道出了什么问题。
有人可以帮助我吗?
谢谢。
下面是控制器功能
public function store(PhotoGalleryRequest $request)
{
$input = $request->all();
$gallery = new PhotoGallery($input);
$filePath = trans('main.photo_gallery.image');
// File Upload
if ($input['main_photo']) {
$fileData = PhotoGallery::uploadFile($input['main_photo'], $filePath);
if ($fileData) {
$fileName = $fileData['fileOriginalName'];
$gallery->main_photo = $fileName;
$gallery->thumb_photo = $fileName;
}
}
$gallery->save();
return redirect()->route('add-more.showAddMore', STCHelper::encryptUrl($gallery->id));
}
下面是模型函数
public static function uploadFile($files,$filePath)
{
$return = [];
if (!empty($files)) {
$destinationPath = base_path() . $filePath;
$thumbPath = base_path() . trans('main.photo_gallery.image_thumb');
if (!file_exists($destinationPath)) {
mkdir($destinationPath, 0777, true);
}
if (!file_exists($thumbPath)) {
mkdir($thumbPath, 0777, true);
}
$filePath = ($filePath) ? base_path().$filePath : base_path();
$fileName = STCHelper::setImageName($files->getClientOriginalName());
$extension = $files->getClientOriginalExtension();
$fileTypes = ['png','jpg','jpeg','JPG'];
if (in_array(strtolower($extension), $fileTypes)) {
$image = Image::make($files->getRealPath());
$image->save($destinationPath. $fileName);
Image::make($files->getRealPath())->resize(268,268)->save($thumbPath . $fileName);
chmod($destinationPath . $fileName, 0777);
} else {
$files->getClientOriginalExtension();
$files->move($destinationPath, $fileName);
chmod($destinationPath . $fileName, 0777);
}
$return['fileName'] = $fileName;
$return['filePath'] = trans('main.photo_gallery.image') . $fileName;
$return['fileType'] = mime_content_type($destinationPath.$fileName);
$return['fileExtension'] = $extension;
$return['fileOriginalName'] = $fileName;
}
return $return;
}