Someone kindly helped me out with version 1.4 by using a different file.php that caused this to happen. However this is incompatible with version 1.5.
I would like this to happen as staff wish to add word worksheets etc which pupils download and work on then save to their area etc.
Any suggestions would be gratefully recieved.
Cheers, Dunks.
A bit of a newbie to the inner workings so your reply poses a couple of quick questions.
1. Is this solution to be added to each doc added as a resource? If so, are you aware of any solution that would force the filetype to do this ie: every word, excel and powerpoint to automatically try to download.
2. Where do I go to add this code?
Many thanks for your assistance.
Duncan
Rob
$forcedownload = optional_param('forcedownload', 0, PARAM_BOOL);
Changing the 0 after forcedownload', to 1 has had the same effect, but site wide???!!!
Hope this may be of use, many thanks for your help. Out of interest where are you based? Always interested to see where I am receiving help from as this is such a great global community!
I am Sandhurst in Berkshire, UK.
www.sandhurst.bracknell-forest.sch.uk/moodle is our effort!
I teach high school tech and geography classes (paperless, thanks to Moodle) in Torrance, California USA.
Rob
Re: Force users to download resources not view in window.
Previewing office documents in-browser was confusing the hell out of my users. This neatly sidesteps the issue. Thanks Duncan.
Thanks!! I have been looking to do this somehow for quite some time! I had gone to the length of ensuring that all of the computers on our school network had the settings changed at a Windows level to not do this. (Very time consuming!) M$ Office Apps opening in the same window is a real pain.
I am off to change that setting right now!
Thanks!!
Jon
The ability to be able to choose file types to force download and those not to force it what I really need... It is only office documents (.doc, .ppt and .xls ) that need to be forced.
would it be possible to have an if else statement around line 20 that checked for the ending of the file name and changed the parameter accordingly...
Something like...
$relativepath = get_file_argument('file.php');
if ($filetype == "doc") {
$forcedownload = optional_param('forcedownload', 1, PARAM_BOOL);
}
else {
$forcedownload = optional_param('forcedownload', 0, PARAM_BOOL);
}
Would need to define variable $filetype , could even have it as an array that could be defined with all of the file types that we want to force to download, and have this settable in the site configuration.
Any pointers for this one? Would be a very useful feature, and stop Microsoft office from changing the way people want their sites to operate.
Jon
It may be a lot of work to add the ?forcedownload=1 to links after the fact, but it does provide the flexibility that you need.
Rob
Those teachers that had a specific case, that needed files to be downloaded that were by default not, could easily be shown the parameter for their needs. The amount of time required for me to change every single Microsoft Office link through out our whole Moodle install is completely unfeasible. (It would take days!!!) I think that this solution would prove a lot more useful, and could even be incorporated into the site config page, so that the admin can set the file types there that they want to be downloaded. (No need to go into the code!)
I am going to have a look at my PHP books tonight when I get home and brush up on regular expressions, as I am sure that I can get this to work, at least within the code.. Then I will look at incorporating it into the site config page...
I will keep you all posted.
Jon
____________________________________
Umm so thought this might work but it doesn't....
if ($mimeinfo == 'doc') {
$forcedownload = optional_param('forcedownload', 1, PARAM_BOOL);
} else if ($mimeinfo == 'xls') {
$forcedownload = optional_param('forcedownload', 1, PARAM_BOOL);
} else if ($mimeinfo == 'ppt') {
$forcedownload = optional_param('forcedownload', 1, PARAM_BOOL);
} else {
$forcedownload = optional_param('forcedownload', 0, PARAM_BOOL);
}
I am trying to use the array that is defined in lib/filelib.php
This array is already defining all of the file types, and I thought I would be able to just use the element of that array to check whether we want it to force download or not... Back to the books I think.....
Right-click link, choose 'Save Target As' command saves an awful lot of hassle!
Regards.
Some staff already direct students to right click and "Save As" but there are many staff who are only just getting used to uploading resources, let alone giving technical instructions to students!
Modify lib/filelib.php to include code highlighted in yellow
function send_file($path, $filename, $lifetime=86400 , $filter=0, $pathisstring=false, $forcedownload=false) {
global $CFG;
if (mimeinfo('type', $filename)=='application/vnd.ms-powerpoint'){
$forcedownload=true;
}
For some reason, adding ?forcedownload=1 to the filename doesn't work for me in 1.8. It used to in 1.6.
I cannot force users to download using the file.php or the lib/filelib.php method. Only adding the code to each individual file works at upload works and I do not want to be restricted to this method.
Is anyone else having this issue? II have tested on pc's with IE6 & IE7 - same result, always opens in the browser. The school has another .asp system running and this does force users to download so I can't believe it's a system setting???
I've created a more elegant hack for forcing files to download.
See:
http://moodle.org/mod/data/view.php?d=13&rid=1115
Re: Force users to download resources not view in window.
Hi Guy,
Many thanks for this hack ,which is indeed quite elegant. We had a problem here where some of our Vista installations had a problem with downloading and opening .doc files from links to files rather than resources (where you can set the 'force download' option). This was discussed here.
After applying your solution things seem to work fine, more testing is needed still but things look promising.
Christoph
Re: Force users to download resources not view in window.
Hi,
I have installed moodle1.9.2 but i am having problems with fourcedownload when i am adding a new resource with load button and with check box of forcedownload Its say an Error: Message that : "Could not add an instance of the resource.". I Had tried with fourm got the solutions with patches to add in file.php nad resource.class.php and modedit.php but all of the moodle version 1.9 only hence not working please can any one answer me.
option to force download files in Moodle 1.9 Stable version..
IN VAIN!!!
I am frustrated. The thing I want to ask Moodle is : why don't you update the stable version and put the version in which the MDF- resolved version of users being able to download the resource files (not only pdf but also word files).
I am tired to trying to hack the resource.class.php, the file.php, lib/filelib.php and whatever else!!
Is this open source: with enough eyeballs, all bugs are not present!???
I even took the courage to install the version 1.7 hoping that this bug would not be present there but all the FILES STILL ARE BEING OPENED IN A NEW WINDOW.
Re: Force users to download resources not view in window.
Re: Force users to download resources not view in window.
i've tried applying this parameter.
but it does not work.
Even the forcedownload checkbox is here.
still no effect
Re: Force users to download resources not view in window.
This aside, IE7 seems to behave more like Firefox with files than IE6. Even if I do not check the checkbox, IE7 still opens a dialog box asking if I want to save the file. What browser and OS are you using? Can you reproduce the issue from other computers?
Rob
Re: Force users to download resources not view in window.
*shameless bump, but perhaps useful for cross reference*
This ?forcedownload=1 business also works well against annoying Windows Security popups.