You can not download file from link in Hosting- The file is embedded in the page - moodle 2.8.3

You can not download file from link in Hosting- The file is embedded in the page - moodle 2.8.3

by Cristhian Acosta Chambers -
Number of replies: 0

Good morning.++


I'm working with moodle in building a block.

To which I have given you the functionality to download files through a link. The point is that in the development environment runs the file download. It therefore for testing I got on a hosting where I have to test development before sending production.

Well here is the link to download the file but not download the file remains embedded in the page.

I have enough time trying to solve the problem but I have not been able to find help.

It is worth mentioning that before this happened I had problems with corrupted files when downloading which also cost me to research and searching can find the solution but I take some time to find the problem which sent me to delete certain lines of a file to make it work.

He solved as indicating this post


https://tracker.moodle.org/browse/MDL-47532


The most disconcerting is that going to the database in which you can upload and download files (Please reference this activity for the download code) and this runs smoothly, you should download the file as activity.


The problem in my option to download the file becomes embedded in the page (already uploaded the block in hosting).


Worse local environment works.


This function code that indicates the plugin to download:

function block_ugtitulacion_pluginfile($course, $cm, $context, $filearea, 


                                       $args, $forcedownload, array $options=array()) {


    global $SESSION;


    // Check the contextlevel is as expected - if your plugin is a block, this becomes CONTEXT_BLOCK, etc.


    //if ($context->contextlevel != CONTEXT_COURSE) {


    if ($context->contextlevel != CONTEXT_BLOCK) {


        return false; 


    }


    // Make sure the user is logged in and has access to the module (plugins that are not course modules should leave out the 'cm' part).


    require_login($course, true);


    // No check for capability, because everybody needs to see it


    // Check the relevant capabilities - these may vary depending on the filearea being accessed.   


    if (!has_capability('block/ugtitulacion:addinstance', $context)) {


        return false;


    }


    // Leave this line out if you set the itemid to null in make_pluginfile_url (set $itemid to 0 instead).


    $itemid = array_shift($args); // The first item in the $args array.


    // Use the itemid to retrieve any relevant data records and perform any security checks to see if the


    // user really does have access to the file in question.


    // Extract the filename / filepath from the $args array.


    $filename = array_pop($args); // The last item in the $args array.


    if (!$args) {


        $filepath = '/'; // $args is empty => the path is '/'


    } else {


        $filepath = '/'.implode('/', $args).'/'; // $args contains elements of the filepath


    }


    // Retrieve the file from the Files API.        


    $fs = get_file_storage();


    $file = $fs->get_file($context->id, 


                          $SESSION->bloque,


                          $filearea, $itemid, $filepath, $filename);


    if (!$file) {


        return false; // The file does not exist.


    }   

// We can now send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering. 


    // From Moodle 2.3, use send_stored_file instead.


     send_stored_file($file, 0, 0, true, $options); //Funciona en el local


}


Please help me someone who can no longer where further research.


Thanking you in advance for your valuable help.


Nota:  translation


Deputy print the file embedded in the page.


Attachment documentourl.png
Average of ratings: -