Failed to save entry: Failed to move uploaded file

Issue Summary:

I am encountering an error when trying to upload media files On my Contacts page. The error message is: Failed to save entry: Failed to move uploaded file.

Environment:
Operating System:** Linux
Web Server:** Nginx
PHP Version:** 7.4 (FPM)

Grav Root Directory: /var/www/grav/grav-admin

PHP Configuration (php.ini):
file_uploads = On
upload_tmp_dir = /var/www/html

Actions Taken to Resolve the Issue

  1. Checked Directory Permission
    Ensured that the upload_tmp_dir directory (/var/www/html) and the target directory for uploads have the correct permissions and are writable by the web server.

2.PHP Configuration:

  • Verified the upload_tmp_dir setting in the php.ini file is correct and points to a writable directory (/var/www/html/tmp).
  • Confirmed that the file_uploads, upload_max_filesize, and post_max_size settings are correctly configured.
  • Restarted Services:
  • Restarted PHP-FPM and Nginx to apply configuration changes.
  • Created a phpinfo.php File:
  • Verified PHP configuration settings by creating and accessing a phpinfo.php file, confirming the correct upload_tmp_dir and other settings are loaded.
    1. Checked Grav Configuration:
    • Reviewed and confirmed settings in system.yaml and other relevant configuration files in Grav.
  1. Debugging Logs:
  • Checked Grav and PHP-FPM logs for any related error messages that could provide more context about the issue.

Additional Information

phpinfo() output related to file uploads:

  • upload_tmp_dir: /var/www/html/tmp
  • upload_max_filesize: 10M
  • post_max_size: 10M
  • file_uploads: On
    can someone help me resolve issue?

Don’t remember now for sure, but I think I had some issues with flex objects and media too. Change contacts to be stored in folders instead of files. I think something doesn’t work when there’s no folder related to flex object to save file to.

Can’t test this myself now, but I have a vague memory of having something similar

The problem is the <Media works on other pages! but just not works for my People pages!

Are you uploading an image to each contact or just to a normal page?


So as screenshots shows, there is part! Image (that works perfectly), and on the end of the page there is a Media!
that after uploading any file, and click on the save gives me this error.

but in this screenshot, (another page)


as you can see the file is uploaded and can be used in the Textarea without any problem

What’s the Directories config in /admin/plugins/flex-objects? I see classes save location is a folder and contacts - as I mentioned previously - is a single JSON file


Exactly that I noticed right now! Classes are separate objects but Contacts are single JSON file!

I gave you an example of each object!
This is a one Record on the Contacts:: JSON file:
{
“3b12c3d3761d9e6d06d785559fb6c7e0”: {
“published”: true,
“image”: {
“user/data/flex/contacts/TorrilhonM_2023.jpg”: {
“name”: “TorrilhonM_2023.jpg”,
“type”: “image/jpeg”,
“size”: 226234,
“path”: “user/data/flex/contacts/TorrilhonM_2023.jpg”
}
},
“active”: true,
“object_media”: {
“X-Wing-Fighter-from-Office-Supplies.jpeg”: {
“name”: “X-Wing-Fighter-from-Office-Supplies.jpeg”,
“type”: “image/jpeg”,
“size”: 31138,
“path”: “X-Wing-Fighter-from-Office-Supplies.jpeg”
},
“DSC_4900-TitelBild_BlogRelaunch-scaled.jpg”: {
“name”: “DSC_4900-TitelBild_BlogRelaunch-scaled.jpg”,
“type”: “image/jpeg”,
“size”: 373881,
“path”: “DSC_4900-TitelBild_BlogRelaunch-scaled.jpg”
}
}
},

and this is the classes Object:
{
“published”: true,
“archiveable”: true,
“title”: “Mathematical Modelling with PDEs”,
“semester”: “Summer”,
“year”: 2024,
“content”: “![Non-Equilibrium Gas Dynamics](classes://82a2878eaff3edacaee9664f189d6bd5/TeaserPDE.jpg?”,
“category”: “Lecture”,
“object_media”: {
“LectureNotes_2018_SimonMaertens.pdf”: {
“name”: “LectureNotes_2018_SimonMaertens.pdf”,
“type”: “application/pdf”,
“size”: 536582,
“path”: “LectureNotes_2018_SimonMaertens.pdf”
},
“TeaserPDE.jpg”: {
“name”: “TeaserPDE.jpg”,
“type”: “image/jpeg”,
“size”: 280251,
“path”: “TeaserPDE.jpg”
}
},
}

and do you meant this directories in Plugins/flex-objects ?

  1. Please read through this pinned post and format your code. I honestly didn’t even try to read the unformatted code parts
  2. You can probably add contacts to that YAML config, but I was pointing to Admin url

I apologize for the unformatted code parts,
I just realize that.

For the directories configuration in the Flex Objects plugin, my setup is as follows:

Classes (for example): The save location is set to a folder, so each class has its own dedicated folder.
Contacts: The save location is set to a single JSON file, meaning all contacts are stored in one file without individual folders.

I found out that I have to change this Storage in Contacts.yaml from

# Storage class, use single file storage (does not support images and assets)
      #class: 'Grav\Framework\Flex\Storage\SimpleStorage'
      #options:
        #formatter:
          # File formatter class, in this case the file is stored in markdown
          #class: 'Grav\Framework\File\Formatter\JsonFormatter'
        # JSON file where all the objects will be stored
        #folder: user-data://flex/contacts/contacts.json

to:

    # Storage class
    storage:
      class: 'Grav\Framework\Flex\Storage\FolderStorage'
      options:
        folder: user-data://flex/contacts

and i separated each object to a folder and with own item.json

For Example: this Object in contacts.json

to a separated file :

But when add an image like the screenshot, to object manually!

i get an Error:

and when i do it from admin panel I get this err:

Did you manually create contacts folder? Maybe permissions issue. Or try to find how contacts are different from classes