When using IMCE to attach a file to a field, you will get the following error if your field is setup to use private files:
"The selected file could not be used because the file does not exist in the database."
To me it seems like the $file_directory_prefix in filefield_source_imce_value() is incorrect when private files are being used.
When private files are being used, $file_directory_prefix is the path of your private files folder (in my case "sites/default/private"), while I think this should always be "system/files" for private files.
Otherwise the preg_replace will fail, which will result in a query that will always have an empty result, which will in turn result in the error.
Comment | File | Size | Author |
---|---|---|---|
#8 | filefield_sources-private-files-fix-1853946-3.patch | 778 bytes | e5sego |
#5 | filefield_sources-private-files-fix-1853946-2.patch | 879 bytes | hepabolu |
#1 | filefield_sources-private_files_fix-1853946-1.patch | 680 bytes | Daluxz |
Comments
Comment #1
Daluxz CreditAttribution: Daluxz commentedHere's a patch.
Comment #2
Dubs CreditAttribution: Dubs commentedThanks for taking to time to write and submit this module.
The patch works - can it please be submitted?
Comment #3
quicksketchHi guys. Thanks for this patch. I think you're correct. This patch looks like it would fix some issues with private files, but it wouldn't fix the situation where private files are being used by Clean URLs are turned off. For now I've committed this patch anyway, since it solves most of the problem. I'm moving this to needs work for the second part of the problem.
Comment #4
zikaelismik CreditAttribution: zikaelismik commentedIs there any news about this? I've installed latest version but still i get the same message
"The selected file could not be used because the file does not exist in the database."
when trying to reference an existing file (uploaded as private).
Comment #5
hepabolu CreditAttribution: hepabolu commentedI've modified the code in the patch to allow extra characters between the base path and the 'system/files'. For me, that was necessary because I have language codes in the URL after the base path. This is my first patch file, so please let me know if it's not ok.
Comment #7
e5sego CreditAttribution: e5sego commentedI run into same problem as hepabolu with setup having language negotiation by path prefix enabled. His patch did not work for me, so I created another one.
Comment #8
e5sego CreditAttribution: e5sego commented