Question

I am trying to upload files to the server, but after i submit the form i always get a Controller method not found error i dont know where am i going wrong. Or if any good tutorial for this purpose?

this is my form

{{ Form::open(array('files' => true , 'action' => array('ProfileController@multiUpload'  ))) }}
{{ Form::file('file[]', array('multiple'=>true))}}
{{ Form::hidden('folder', $data->username) }}
{{ Form::submit('Upload To Gallery') }}
{{ Form::close() }}

this is my route

Route::post('multiupload', 'ProfileController@multiUpload');

and this is my controller method

class ProfileController extends BaseController
{
    public function multiUpload()
    {
        if (Input::hasFile('file[]')) 
        {
            $all_uploads = Input::file('file[]');
            $folder = Input::get('folder');

            // Make sure it really is an array
            if (!is_array($all_uploads))
            {
                $all_uploads = array($all_uploads);
            }

            $error_messages = array();

            // Loop through all uploaded files
            foreach ($all_uploads as $upload)
            {
                // Ignore array member if it's not an UploadedFile object, just to be extra safe
                if (!is_a($upload, 'Symfony\Component\HttpFoundation\File\UploadedFile'))
                {
                    continue;
                }

                $validator = Validator::make(
                    array('file' => $upload),
                    array('file' => 'required|mimes:jpeg,png|image|max:5000')
                );

                if ($validator->passes()) 
                {
                    Image::upload($upload, 'uploads/'.$folder , true);
                } 
                else 
                {
                    // Collect error messages
                    $error_messages[] = 'File "' . $upload->getClientOriginalName() . '":' .    $validator->messages()->first('file');
                }
            }

            // Redirect, return JSON, whatever...
            return $error_messages;
        } 
        else 
        {
            // No files have been uploaded
        }
    }
}
Was it helpful?

Solution

Your method should be lowercase change multiUpload() to multiupload() and try again.

OTHER TIPS

Maybe the error is cause by the misspelling of BaseContoller

Change

class ProfileController extends Basecontroller

To

class ProfileController extends BaseController
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top