0

My Form

{{ Form::open(array('url' => 'upfile', 'files' => 'true', 'method' => 'post', 'class' => 'form')) }}
        <p>Sólo se admiten archivos en formato .pdf y no mayor a 127MB</p>
        <p>
        {{ Form::file('expediente', array('class' => 'text-field column_one', 'required' => 'required')) }}
        </p><br>
        <p>
        {{ Form::text('nombrearchivo', null, array('class' => 'text-field column_one', 'required' => 'required', 'placeholder' => 'Nombre del Expediente.')) }}
        </p><br>

        {{ Form::hidden('username', $username) }}

        <p style="color: red;">
            <ul>
            @foreach ($errors->all() as $message)
                <li style="color:red;">{{$message}}</li>
            @endforeach
            <ul>
        </p>
        {{ Form::submit('Añadir Expediente', array('class' => 'submit submitNavy submitForm')) }}
 {{ Form::close() }}

My Controller:

public function saveExpediente(){
    ini_set("memory_limit","7G");
    ini_set('upload_max_filesize', '127M');
    ini_set('post_max_size', '127M');
    ini_set('max_input_time', 0);
    ini_set('max_execution_time', 0);
    set_time_limit(0);
    ignore_user_abort(true);

    $rules = array(
        'username' => 'required|exists:users,username',
        'expediente' => 'required',
        'nombrearchivo'    =>  'required|min:5'
    );

    $validator = Validator::make(Input::all(), $rules);
    //$fileExtension = Input::file('expediente')->guessClientExtension();
    $file = Input::file('expediente');
    if ($validator->fails()) {
        //dd($file);
        return Redirect::back()
            ->withErrors($validator) // send back all errors to the login form
            ->withInput(); // send back the input (not the password) so that we can repopulate the form
    }/*else if ($fileExtension != 'pdf'){
        $validator->failed();
        return Redirect::to('upload')->withErrors([
            'expediente' => 'El archivo debe estar en formato PDF!',
        ])->withInput();
    }*/else {

        File::makeDirectory('expedientes/'.Input::get('username'), 0770, true, true);
        Input::file('expediente')->move('expedientes/'.Input::get('username'),Input::file('expediente')->getClientOriginalName());

        $expediente = new Expediente;
        $expediente->username =  Input::get('username');
        $expediente->archivo = Input::file('expediente')->getClientOriginalName();
        $expediente->nombrearchivo = Input::get('nombrearchivo');
        $expediente->save();

        return Redirect::back()->with('message', 'Se añadió correctamente el expediente al usuario.')->with('tipo','message-success');
    }
}

When I'm uploading bigger than 8mb laravel returning NULL, like fields they were empty. I already got the value of variables PHP.init. I'm use Laravel 4.2 and Apache, need upload files size with 25-40 mb. If I try dd(Input::file('expediente')) return NULL

4
  • Do you check your maximum upload file size in php.ini? Commented Apr 8, 2015 at 13:47
  • And post_max_size too? Commented Apr 8, 2015 at 13:55
  • Oh.. Not! It's 7MB... Now we are sure this it's the problem. The App it's at a share-server. Can't we change variable value without contacting to Company support? Commented Apr 8, 2015 at 14:05
  • 1
    You can't use 'ini_set" for that. You have to contact your host company for that. Maybe they have a solution for that. Commented Apr 9, 2015 at 10:04

2 Answers 2

1

You need to increase the memory limit of file upload. You could do this by mentioning the limit size in the beginning of the controller.

ini_set('memory_limit', 'size');

For example:

ini_set('memory_limit', '40M');

You may also need to mention the enctype (encoding type) in the form

Example:-

{{ Form::open(array( 'url' => 'upfile', 'method' => 'post', 'class' => 'form', 'enctype' => 'multipart/form-data' )) }}

and may be you dont need this 'files' => 'true'

Sign up to request clarification or add additional context in comments.

Comments

1
  1. Check the error:

    $request->file('image')->getErrorMessage()

  2. If error looks like:

    The file "image_name.jpeg" exceeds your upload_max_filesize ini directive (limit is 2048 KiB)

  3. In blank page execute the next command to locate php.ini:

    <?php phpinfo() ?>

  4. In php.ini file edit the next lines:

    post_max_size

    upload_max_filesize

  5. Increase the memory limit (by default is 2M), you can try with 10M.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.