April 2, 2012 Jimmy

Parse an uploaded CSV file in 2 lines in PHP/CakePHP

Nasty but gets it done:

or, if you want to be even more crazy, in 1 (note, config options are inline but I left the assignments so they are findable):

or, if you want it to be one expression, but more readable:

In the examples above, I’m assuming you already know the temporary name of the uploaded file. In regular PHP, you could prepend this code with

In CakePHP, you might just replace $tmpname with $this->data[‘Whatever’][‘csv’][‘tmp_name’];
This kind of assumes you had done something like this on the form page:

,

Leave a Reply

Your email address will not be published. Required fields are marked *

Do NOT follow this link or you will be banned from the site!