use storage for upload image first
public function store(Request $request){
Post::create({
'image' => $request->image->store('directory for upload')
})
}
and auto hash image name
I have an application that needs to resize image for several diminutions so I used image intervention to do that to me and it work like charm on localhost and save the uploaded images in the place that it should save file in it but when it was uploaded to cpanal something weird happened it save the files on public_html with full path that it should save on it (Ex: the name of the image should be 62170e1bc306e.png but when i uploaded it its name was public_html\public\images\small\62170e1bc306e.png)
my code
static function storePreview($file,$dimintionsArray,$model) {
$name = uniqid() . '.png';
$dir = public_path() . "/images";
$imageInstance = self::create([
'name' => $name,
'use_for' => 'preview',
]);
$image = $file->getRealPath();
foreach($dimintionsArray as $key => $dimintionValue) {
$dimintions = explode('X',$dimintionValue);
self::resize($image,$dimintions)->save($dir."\$key\".$name);
}
$model->image_id = $imageInstance->id;
$model->save();
}
thanks in advance
Please or to participate in this conversation.