[英]Issue with file edit in PHP using file_put_contents (Laravel)
大家下午好,我遇到了一個我無法解決的奇怪問題,我希望有人能幫助我找出導致此問題的原因。 為了提供一些上下文,我允許用戶在產品上存儲一組圖像,然后使用 laravel-stapler 包存儲它們,該包按以下方式配置:
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->hasAttachedFile('image', [
'styles' => [
'thumbnail' => '500x500#',
'large' => '800x800#'
],
'url' => '/media/image/:id/:style/:filename',
'default_url' => '/img/category-placeholder-greyscale.jpg',
'convert_options' => [
'jpeg_quality' => 60
]
]);
}
圖像保存在三個文件夾中:
../路徑到圖像/原始/文件名
../路徑到圖像/縮略圖/文件名
../路徑到圖像/大/文件名
保存這些圖像后,我使用croppie.js 來旋轉和編輯它們。 在用戶編輯和裁剪它們並提交后,圖像作為 base64 發送到控制器,控制器在下面縮短為僅相關部分:
$imageData = $request->get('imagebase64');
list(, $imageData) = explode(';', $imageData);
list(, $imageData) = explode(',', $imageData);
$imageData = base64_decode($imageData);
// $image is loaded up through dependency injection
$path = public_path('/path' . '/large/' . $image->image_file_name);
$path2 = public_path('/path' . '/original/' . $image->image_file_name);
file_put_contents($path, $imageData);
file_put_contents($path2, $imageData);
您可能需要編輯 .htaccess 文件以授予這些文件的權限
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.