So i'm using intervention package to save and also resize my image if it has to big resolution, but i get MethodNotAllowedHttpException when i tried to test with uploading big images (around 10 mb ).
so i do some research over here and the net, there is indeed some answer but none of them work with me, i wonder why is it happen?
try{
$img = Input::file('gambar');
if(!empty($img)){
$file_max = ini_get('upload_max_filesize');
$file_max_str_leng = strlen($file_max);
$file_max_meassure_unit = substr($file_max,$file_max_str_leng - 1,1);
$file_max_meassure_unit = $file_max_meassure_unit == 'K' ? 'kb' : ($file_max_meassure_unit == 'M' ? 'mb' : ($file_max_meassure_unit == 'G' ? 'gb' : 'unidades'));
$file_max = substr($file_max,0,$file_max_str_leng - 1);
$file_max = intval($file_max);
$filename = $img->getClientOriginalName();
$size = $img->getSize();
if ($size < $file_max){
if($this->save_image($img,$artikel,$filename)){
$artikel->update(array(
'judul' => $judul,
'content' => Input::get('content'),
'kategori' => Input::get('kategori'),
'status' => Input::get('status'),
'pilihan' => Input::get('pilihan'),
'gambar' => $filename
));
}else{
return Redirect::back()->withErrors($validator)->withInput();
}
}else{
return Redirect::back()->withInput()->with('errormessage','El tamaño del archivo debe ser menor que %smb.',$file_max);
}
}
}catch(Exception $e){
return Redirect::back()->withInput()->with('errormessage','The file size should be lower than %s%s.',$file_max,$file_max_meassure_unit);
}
and here is my save_image function
function save_image($img,$artikel,$filename){
list($width, $height) = getimagesize($img);
$path = public_path('images_artikel/');
File::delete($path . $artikel->gambar);
if($width > 1280 && $height > 720){
if(Image::make($img->getRealPath())->resize('1280','720')->save($path . $filename))
return true;
else
return Redirect::back()->withInput()->with('errormessage','Terjadi kesalahan dalam penyimpanan');
}else{
if(Image::make($img->getRealPath())->save($path . $filename))
return true;
else
return Redirect::back()->withInput()->with('errormessage','Terjadi kesalahan dalam penyimpanan');
}
}
i also tried to use validation rules in my models but not working...
private $file_max;
function _construct(){
$file_max = ini_get('upload_max_filesize');
$file_max_str_leng = strlen($file_max);
$file_max_meassure_unit = substr($file_max,$file_max_str_leng - 1,1);
$file_max_meassure_unit = $file_max_meassure_unit == 'K' ? 'kb' : ($file_max_meassure_unit == 'M' ? 'mb' : ($file_max_meassure_unit == 'G' ? 'gb' : 'unidades'));
$file_max = substr($file_max,0,$file_max_str_leng - 1);
$file_max = intval($file_max);
}
// Add your validation rules here
public static $rules = [
'judul' => 'required|between:5,255',
'content' => 'required',
'gambar' => 'image|mimes:jpeg,jpg,png,bmp|max:{$file_max}'
];
here is my route
Route::resource('artikels','AdminArtikelsController');
and my form
{{ Form::model($artikel, array('route' => array('admin.artikels.update',$artikel->id), 'method' => 'put', 'files' => true)) }}
so is there other solution?