Form upload files: Unable to create directory

I have a standard form page set up, everything works except File Field upload. I can see the drag and drop box on the front end, but when I chose the file I get:
Unable to create directory: error on a red alert tooltip.
In console I have a 500 (Internal Server Error) and in XHR I get the following:

{
    "error": {
        "type": "RuntimeException",
        "message": "Unable to create directory: ",
        "code": 0,
        "file": "/home/grav/www/site/html/system/src/Grav/Common/Filesystem/Folder.php",
        "line": 468
    }
}

This happens both on local dev (Windows 10 with WSL and apache2) but also on the remove DigitalOcean droplet with Ubuntu and Nginx.

Is there a know issue or an I doing something wrong? I’ve tested with a very simple form as an example of the docs, everything works, emails are send, but the file is not uploaded in the directory and also not send as an attachment like I would like.

There are lots of known issues with file uploads and there have been for a while. Some of them have workarounds. Did you search the form plugin’s repository for issues? Don’t expect that if you add an issue there that it will be fixed soon either. You can see how old some of those issues are.

I can make one suggestion to check. What are the permissions in the destination folder? Have you tried creating the destination folder manually, with the required permissions and owner? That’s not a solution but might help you troubleshoot or work around this.

1 Like

@filo91, Since this happens on all of your installations on different platforms and webservers, the most common denominators are Grav and your form definition. Would you mind sharing your form definition?

I cannot reproduce this issue on Windows 11, WSL, Apache, using the following form definition:

form:
  name: myform
  fields:
    myfile:
      type: file
  buttons:
    submit:
      type: submit
  process:
    message: thank you

After digging though all of Grav configuration settings, I found I had “Initialize Session” turned off, after switching it on, now the upload works, doesn’t though the error and saves the file in the folder as expected. It was impossible to figure this out from the error and it’s not mentioned in the documentation that you need this setting enabled. The other parts of the form were working fine, I had another form running for years without using a session.

@filo91, Please mark your post as being solved and open a new questions regarding the sending of the file though email.

I guess the session is required, because the uploading of files happens in two stages

  • Stage 1: On dropping a file onto the field, the file is submitted to the server using an async call. The file is then stored in a temp file. The location needs to be remembered in the session object.
  • Stage: 2: When submitting the form, the temp file is being fetched and moved into the correct location.
1 Like