cugurel's avatar

Uploading Image

Hello every one. I want to upload website logo to database. Here is my admin controller codes. But when i upload a jpeg file, it says error.

public function post_ayarlar(Request $request) { if(isset($request->logo)) {

        $validator = Validator::make($request->all(), [
            'logo' => 'mimes:jpg,jpeg,png,gif'
        ]);
        if ($validator->fails()) {
            return response(['durum' => 'error', 'baslik' => 'Hatalı', 'icerik' => 'Dosya uzantısı geçerli değil...']);
        }

        $logo = Input::file('logo');
        $logo_uzanti = Input::file('logo')->getClientOriginalExtension();
        $logo_isim = 'logo.' . $logo_uzanti;
        Storage::disk('uploads')->makeDirectory('img');
        Image::make($logo->getRealPath())->resize(222.108)->save('uploads/img' . $logo_isim);
    }
    try{
        unset($request['_token']);
        if(isset($request->logo))
        {
            unset($request['eski_logo']);
            Ayarlar::where('id',1)->update($request->all());
            Ayarlar::where('id',1)->update(['logo=>logo_isim']);
        }
        else{
            $eski_logo=$request->eski_logo;
            unset($request['eski_logo']);
            Ayarlar::where('id',1)->update($request->all());
            Ayarlar::where('id',1)->update(['logo=>logo_isim']);
        }

        return response(['durum'=>'success','baslik'=>'Başarılı','icerik'=>'Kayıt Başarıyla Tamamlandı.']);
    }
   catch (\Exception $e)
   {
       return response(['durum'=>'error','baslik'=>'Hatalı','icerik'=>'Kayıt Başarıyla Tamamlanamadı.']);
   }

}

}

0 likes
15 replies
cugurel's avatar

@Snapey i can not upload jpeg file. He returns json but says his format not valid.

cugurel's avatar

@Snapey it wast first but i added use Validator and it is okey but when i want to add jpeg file, it says the file extension is not valid.

cugurel's avatar

There is no exception error. But when i upload jpeg file, it says the file format is not valid. @hassanibrahim

cugurel's avatar

This JSON file does not appear to have any style information associated with it. The document tree is shown below. Object baslik:"Hatalı" durum:"error" icerik:"Dosya uzantısı geçerli değil..."

When i upload file this shown but actually format is okey

@Snapey

hassanibrahim's avatar

@cugurel another thing, try to set the validation rule to:

'logo' => 'mimetypes:image/gif, image/png, image/jpeg'

Please or to participate in this conversation.