Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

theUnforgiven's avatar

Uploading 8.5MB CSV

Hi All,

I'm using Homestead locally to develop a bookstore and my client needs to upload a CSV file, the only thing is it's 8.5MB and it tried to upload it and extract the DB but after a minute or so it shows problem loading page

My question is, is there a quicker way to do this to speed up the upload process for such a big file or are there some settings within Homestead I can alter to allow for this?

0 likes
41 replies
theUnforgiven's avatar

I've added

ini_set('upload_max_filesize', '20M');
ini_set('post_max_size', '20M');
ini_set("memory_limit", '256M');

To my method within my controller, to see if this will work, will post an update shortly.

theUnforgiven's avatar

Yeah just thought that so added set_time_limit(0); at the top of the script.

citricsquid's avatar

There's a variety of potential causes, if you've correctly configured PHP the next step is to check your web server, nginx has a client_max_body_size option that defaults to 1mb, that could be the problem you're running into. As far as I know laravel doesn't use the error problem loading page anywhere, so that's most likely your browsers display for an unexpected response from the server, what http status code is the request responding with? That will allow you to narrow down the problem.

theUnforgiven's avatar

Tried in Chrome and get 413 Request Entity Too Large nginx/1.6.0

theUnforgiven's avatar

Tried to find/edit the nginx.conf but get this:

vagrant@homestead:/$  find / -name "nginx.conf"
find: `/var/spool/cron/atjobs': Permission denied
find: `/var/spool/cron/atspool': Permission denied
find: `/var/spool/cron/crontabs': Permission denied
find: `/var/spool/rsyslog': Permission denied
find: `/var/lib/polkit-1': Permission denied
find: `/var/lib/mysql': Permission denied
find: `/var/lib/php5': Permission denied
find: `/var/lib/postgresql/9.3/main': Permission denied
find: `/var/lib/puppet': Permission denied
find: `/var/log/mysql': Permission denied
find: `/var/log/puppet': Permission denied
find: `/var/log/nginx': Permission denied
find: `/var/cache/ldconfig': Permission denied
find: `/home/ubuntu/.ssh': Permission denied
henrique's avatar

Check at /etc/nginx, config files are generally at /etc and logs at /var

theUnforgiven's avatar

Ok i've added client_max_body_size 20M; tot the nginx.conf file do i need to reload now if so how?

NormySan's avatar

You will need to do a:

sudo service nginx restart

Edit: Fixed typo

1 like
theUnforgiven's avatar

That seems to be working, I think just getting Call to a member function move() on a non-object error now so need to fix that.

theUnforgiven's avatar

Now it's not even uploading the file to the directory or nothing and when I did dd(Input::get('file')) it returned null

My code:

 public function upload()
    {


       if (Input::hasFile('file')) {

            $file = Input::file('file');

            $name = time() . '-' . $file->getClientOriginalExtension();
            $moved = $file->move(public_path() . '/uploads/csv', $name);


            $csv = new Reader($moved);
            $csv->setOffset(0);
            $nbInsert = $csv->each(function ($row) use (&$sth) {
            DB::table('books')->insert(

                    array(
                        'ref' => (isset($row[0]) ? $row[0] : ''),
                        'date' => (isset($row[1]) ? $row[1] : ''),
                        'sold' => (isset($row[2]) ? $row[2] : ''),
                        'author' => (isset($row[3]) ? $row[3] : ''),
                        'title' => (isset($row[4]) ? $row[4] : ''),
                        'place_date' => (isset($row[5]) ? $row[5] : ''),
                        'description' => (isset($row[6]) ? $row[6] : ''),
                        'price' => (isset($row[7]) ? $row[7] : ''),
                        'keywords' => (isset($row[8]) ? $row[8] : ''),
                        'classification' => (isset($row[9]) ? $row[9] : ''),
                        'cost' => (isset($row[10]) ? $row[10] : ''),
                        'notes' => (isset($row[11]) ? $row[11] : ''),
                        'isbn' => (isset($row[12]) ? $row[12] : ''),
                        'publisher' => (isset($row[13]) ? $row[13] : ''),
                        'pub_date' => (isset($row[14]) ? $row[14] : ''),
                        'binding' => (isset($row[15]) ? $row[15] : ''),
                        'condition' => (isset($row[16]) ? $row[16] : '')
                    )
                );
                return true;
            });
        }

        return Redirect::to('admin/books')->with('flash_success', 'Upload completed & new data inserted.');
    }

Form:

{{ Form::open(['route' => 'books.upload', 'class' => 'form-horizontal', 'files' => true]) }}

        <p>Upload CSV file</p>
        {{ Form::file('file') }}

        <button class="btn btn-success">Upload</button>

    {{ Form::close() }}
xingfucoder's avatar

I would use your ini_set functions in your application start file. Did you try it?

faisal.arbain@gmail.com's avatar

if the purpose of uploaded file is to be extracted into DB, usually I will not move it into upload folder. I will make my CSV reader read directly from temp folder.

I think you can check first the value of Input::file("file"); first.

dd(Input::file("file"));

then we can see where we should move.

p/s: your form already set to multipart/form-data right?

roderick's avatar

Is this a one-time upload or will your client upload CSV files on a regular basis?

If you need to deliver, you could populate the db without building this into the application and then work on this feature after delivery.

theUnforgiven's avatar

I can upload smaller files yes, multipart is in the form tag and the client will need to do this on a regular basis

theUnforgiven's avatar

Still not able to upload anything bigger than 1MB so no idea what's going on here/.

bashy's avatar

Try without Homestead, I don't use it and it's easy enough to setup the same stuff.

bashy's avatar

I just find developing on local machine is fine, no VM. Ends up being more hassle than it's worth since I develop on my own and know quite a bit about web servers.

theUnforgiven's avatar

Tried with artisan serve but can connect to mysql forgot how to do it and have mysql installed on my mac and dont fancy installing MAMP

theUnforgiven's avatar

There's no 413 response now, but it's not even uploading to the public/uploads folder at all. So not even sure it is the VM but it does however work will smaller files like 1MB, 238kb etc

Next

Please or to participate in this conversation.