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
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.
Checked Grav Configuration:
Reviewed and confirmed settings in system.yaml and other relevant configuration files in Grav.
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
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.
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”: “: 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