-2

I am doing a curl -d @data.csv myserver.com to POST Data to my linux server. Using laravel my routes will route the POST request to a function inside my Controller.php:

    public function endpoint(Request $request)
    {
        $handle = $request->file('data.csv');
        $use = fopen($request->file('data.csv'), "r");
    }

Now the errorlog returns: [2021-06-24 15:44:55] production.ERROR: fopen(): Filename cannot be empty {"exception":"[object] (ErrorException(code: 0): fopen() --> so the expected data.csv ist not arriving, the request seems to be empty. Of course, I googled the issue first. All answers online say this is due to wrong permissions on the folder where the uploaded file is temporarily stored, but where is that? Doing a $temp_file = tempnam(sys_get_temp_dir(), 'Tux'); echo $temp_file; echos /tmp/TuxWk8llX which leads me to belive the default tmp directory is /tmp/. My php.ini says also that /tmp/ is this upload directory (see below). But doing an lson /tmp/ shows it has all permissions: drwxrwxrwt. 1 root root 57 Jun 24 13:28 tmp So why is the request not coming through, any ideas? Thanks in advance, am really confused about by this! :) PS: Might this ; sys_temp_dir = "/tmp" in the php.ini cause the problem?

**php.ini config file**
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
upload_tmp_dir = /tmp

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 200M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

; Directory where the temporary files should be placed.
; Defaults to the system default (see sys_get_temp_dir)
; sys_temp_dir = "/tmp"
  • https://laravel.com/docs/8.x/requests#file-paths-extensions – RiggsFolly Jun 24 '21 at 13:56
  • Ok, can you explain how this can be put to use? ```public function endpoint(Request $request) { $path = $request->path(); \Log::info($path); }``` gives me this log: `[2021-06-24 16:21:07] production.INFO: /` . If that is true, than the default directory to store data is / where I would doubt the application has sufficient permissions to store data, right? – stackoverflow_asker Jun 24 '21 at 14:22
  • https://stackoverflow.com/a/31669672/2310830 – RiggsFolly Jun 24 '21 at 14:22
  • ok so ```public function endpoint(Request $request) { $info = $request->getContent(); \Log::info($info); }``` give the following log: `[2021-06-24 16:29:29] production.INFO: ` so it seems there is just nothing there. – stackoverflow_asker Jun 24 '21 at 14:32

2 Answers2

0

Maybe read the documentation @ https://laravel.com/docs/8.x/requests#retrieving-uploaded-files

$request->file('data.csv') will contain an object of a temp file IF the POST field is named data.csv.

Thomas Huijzer
  • 354
  • 1
  • 7
  • hi, ok so the problem is more how to name the post field correctly? I am using curl -F `'name=data.csv' myserver.com` to post the data. Is that correct? – stackoverflow_asker Jun 24 '21 at 14:16
  • Suggets you dump the content of the request object to see whats actuall there – RiggsFolly Jun 24 '21 at 14:20
  • ok thanks for the suggestion to read documentioan. I found the solution doing it: Adding ``use Illuminate\Http\Request;`` to the routes did the trick for me. Thank you for your help. lel! – stackoverflow_asker Jun 25 '21 at 13:58
0

I found the solution: Adding use Illuminate\Http\Request; to the routes did the trick for me. Thank you for your help.