CrastyCrap's avatar

Image Intervention save function problem

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

0 likes
4 replies
johnDoe220's avatar

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

CrastyCrap's avatar

@johnDoe220 i am trying to resize an image and store that image in specific folder and it work on localhost but on cpanal it save it in public_html and make the name of the file is the path of it like if i want to save an image in folder images/small/image_name it will work on localhost but on cpanal it will save it in public_html and make the name of (images/small/image_name).png

Please or to participate in this conversation.