'Laravel does not get the temppath when upload bigger files

I need to handle a file in a Laravel controller,

TL;DR

How to handle big files through laravel requests?


When I make the request with the small file, its tempPath is normal: /tmp/php3Hijl5 But when I make a request for a large file it comes: /home/p.../public

This can happen because php defines a maximum size in php.ini called upload_max_filesize.

Trying to solve this problem, I'm setting the project to a larger upload_max_filesize:

ini_set('upload_max_filesize', '50M');

But this thing is not reflecting in the project, because when I give ini_get('upload_max_filesize'); it returns a '2M'.

When I try to handle the file with fgetcsv() it says that this tempPath is a directory.

Laravel Error: fgetcsv(): read of 8192 bytes failed with errno=21 Is a directory

Im using dd() to check the file tempPath.

Controller.php

    public function assignToClients(Request $request, $id)
    {
        $file = $request->file('csv_joining_clients');

        if (!$file) {
            return response([
                'message' => 'You have to upload a CSV file'
            ], 400);
        }

        $array = $this->parseCsvToString($file);

        dd($array);
    }

    private function parseCsvToString($file)
    {
        $i = 0;
        $importData_arr = [];

        $tempPath = $file->getRealPath();

        dd($tempPath);

        $file = fopen($tempPath, 'r');

        while (($filedata = fgetcsv($file, 10000, ",")) !== false) {
            $num = count($filedata);

            for ($c = 0; $c < $num; $c++) {
                $importData_arr[$i][] = $filedata[$c];
            }
            $i++;
        }
        fclose($file);

        return $importData_arr;
    }



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source