I hope I am writing at the right place. I have a question about course custom field, especially the text area field.
When I upload a pdf file in a text area custom field in my course and try to download it, Moodle serves me a file called 86400. I loose the file name.
In my plugin renderer, I use the file_rewrite_pluginfile_urls() frunction to convert the @@pluginfile@@ into a URL. The URL is perfectly fine. Moodle finds the file but serve it as 86400 ??
I looked at /customfield/field/textarea/lib.php at line 75
send_file($file, 86400, 0, $forcedownload, $options);
the send_file() method signature is:
/lib/filelib.php line 2426
send_file($path, $filename, $lifetime = null , $filter=0, $pathisstring=false, $forcedownload=false, $mimetype='', $dontdie=false, array $options = array())
I think there is a misplaced argument. The cache lifetime is passed as the $filename (second argument).
Create a course
Create a text area custom field
Go to your course settings and upload a file in the text area
In your front end (I use my plugin renderer) convert the content of the text area with file_rewrite_pluginfile_urls()
Try downloading the file
What do you guys think? Did I do something wrong or is this a bug?
Thank you in advance for your help
Appears to be a bug. Quick way to determine this - change the line and see if it makes a difference.
Thank you for your reply. After a few try (thx to XDebug!) I finally made it work with:
send_file($file, $filename, 86400, 0, true, $forcedownload, '', false, $options);
Now the file download with proper file name.
What do you think? Should I file a bug in the tracker?