parsecsv / parsecsv-for-php

CSV data parser for PHP.
MIT License
678 stars 176 forks source link

File upload #176

Closed insaurabh closed 5 years ago

insaurabh commented 5 years ago

It's not an issue, just a query or a feature request in general.

Is there any method available by which we can use it with a file uploader.

Currently, I uploaded the file in a folder and then passed the file to the method to get the csv data.

gogowitsch commented 5 years ago

I am not aware of any function specific for file uploads.

If you need more help to the same topic, feel free to add to the discussion here. Otherwise, close this issue. Thanks!

You are always welcome to open another issue later.

insaurabh commented 5 years ago

@Fonata

Thank for your suggestion, as if i use the tmp_name i am getting the data.

A sample code without any validation, i used this just to validate.

if (isset($_POST["submit"])) {
    if ($_FILES["fileToUpload"]["size"] > 0) {
        $target_file = $_FILES["fileToUpload"]["tmp_name"];
        $csv = new ParseCsv\Csv();
        $csv->auto($target_file);
        $data =  $csv->data;

        foreach ($data as $key => $value) {
            print_r($value);
            echo "<br/>";
        }
    }
}