Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

Form upload files: Unable to create directory

form plugins solved

Solved by Filippo Masoni View solution

Started by Filippo Masoni 3 years ago · 4 replies · 512 views
3 years ago

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:

JSON
{
    "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.

3 years ago

@filo91:
Is there a know issue or an I doing something wrong?

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
3 years ago

@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:

YAML
form:
  name: myform
  fields:
    myfile:
      type: file
  buttons:
    submit:
      type: submit
  process:
    message: thank you
3 years ago Solution

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.

last edited 11/07/23 by Filippo Masoni
3 years ago

@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

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 46 1 week ago
Plugins · by Xavier, 4 weeks ago
2 55 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1181 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 49 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 73 2 months ago