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.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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?
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.
Still nothing, still doesn't upload.
Could be execution time in PHP.
Yeah just thought that so added set_time_limit(0); at the top of the script.
Still no joy even by adding this.
How does one check the php log on Homestead ?
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.
All i see is http://cl.ly/image/2x153k0L2U2S in Firefox, and there's nothing in the laravel.log file and I've set:
App::fatal(function($exception)
{
Log::error($exception);
});
In app > start > global.php
Tried in Chrome and get 413 Request Entity Too Large nginx/1.6.0
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
Check at /etc/nginx, config files are generally at /etc and logs at /var
You can find the nginx config in /etc/nginx/nginx.conf
You will have to use sudo to edit it.
sudo nano /etc/nginx/nginx.conf
Edit:
What you want to change/add is the client_max_body_size it seems. Here is a link to the nginx docs describing this value:
http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
Ok i've added client_max_body_size 20M; tot the nginx.conf file do i need to reload now if so how?
You will need to do a:
sudo service nginx restart
Edit: Fixed typo
vagrant@homestead:/$ sudo services nginx restart sudo: services: command not found
Found out it's
sudo service nginx restart no 's' on service
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.
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() }}
Anyone?
I would use your ini_set functions in your application start file. Did you try it?
Does it work with a small file?
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?
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.
I can upload smaller files yes, multipart is in the form tag and the client will need to do this on a regular basis
Still not able to upload anything bigger than 1MB so no idea what's going on here/.
Try without Homestead, I don't use it and it's easy enough to setup the same stuff.
@bashy you mean try with built-in server by doing php artisan serve ?
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.
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
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
Please or to participate in this conversation.