I'm having issues validating files with Laravel 3. Whatever I try, the validator passes. So uploading a mp4 when it should not be allowed works.. I know I'm not too far away, but I can't figure it out.
Here is the relevant part of my function my form is posting :
public function post_edit($id)
{
$input = Input::all();
$files = Input::file();
$dev = new Dev();
$upload = new Upload();
$v_upload = Validator::make($files, $upload->rules);
$v_dev = Validator::make($input, $dev->rules);
if($v_dev->passes() && $v_upload->passes()) {
//success
$dev = Dev::find($id);
//save input data to model then save...
$dev->save();
foreach($files as $key=>$file) {
if($file['name'] != '') {
$upload = new Upload;
$upload->for = 'devs';
$upload->for_id = $id;
$upload->name = $file['name'];
$upload->type = $file['type'];
$upload->save();
Input::upload($key, 'public/upload', 'd'.$id.'_'.$file['name']);
}
}
$message = "Success!";
return Redirect::to('/dev/'.$id)->with('message', $message);
}
else {
//failure
dd($v_upload);
}
}
And my model :
class Upload extends Eloquent
{
public static $table = 'uploads';
public static $timestamps = false;
public $rules = array(
'size' => 'max:102400',
'type' => 'mimes:png,jpg,gif,tiff,zip,tgz,css,html,js,php,txt,mp3,psd,csv,xls,xlsx,ppt,doc,docx'
);
}
Also, my array of files (Input::file()
) looks like this:
array(2) {
["upload1"]=>
array(5) {
["name"]=>
string(17) "facebook-logo.jpg"
["type"]=>
string(10) "image/jpeg"
["tmp_name"]=>
string(14) "/tmp/phpEGqXWT"
["error"]=>
int(0)
["size"]=>
int(12939)
}
["upload2"]=>
array(5) {
["name"]=>
string(15) "mobile-icon.jpg"
["type"]=>
string(10) "image/jpeg"
["tmp_name"]=>
string(14) "/tmp/phpygDS1k"
["error"]=>
int(0)
["size"]=>
int(8570)
}
}