Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-83501

X-Sendfile Function Fails with Special Characters in File Names on Nginx

XMLWordPrintable

      The xsendfile function in Moodle's

      lib/xsendfilelib.php

      fails when the file name contains special characters such as ?, and % when using Nginx. This issue results in the function returning an error and the file not being served as expected.

      Steps to Reproduce:

      1. Ensure that the $CFG->xsendfile setting is enabled in the config.php file.

      2. Make Sure $CFG->dataroot directory is writable.

      3. In the root directory of your Moodle installation, create a file named _ test-xsendfile.php_. Add the following code to test-xsendfile.php:

         <?php
         include('config.php');
         $ignored = make_request_directory();
       
         $filename = 'hello % world.txt';
         $path = "$CFG->dataroot/$filename";
         file_put_contents($path, "This is a file called $filename\n");
         send_file($path, $filename, 0, 0, false, true);
         

      4. Open a web browser and navigate to the URL: http://yourmoodleurl/test-xsendfile.php

      5. The file should be downloaded by the browser using the X-Sendfile header. However, you will encounter an error message:

      This site can’t be reached
      The webpage at [https://yourmoodleurl/test-xsendfile.php] might be temporarily down or it may have moved permanently to a new web address.
      ERR_INVALID_RESPONSE
      

        1. Screenshot from 2024-10-21 11-15-54.png
          132 kB
          Rajan Dangi
        2. mdl-83501 passing.png
          680 kB
          Andrew Lyons

            rajandangi Rajan Dangi
            rajandangi Rajan Dangi
            Brendan Heywood Brendan Heywood
            Andrew Lyons Andrew Lyons
            Andrew Lyons Andrew Lyons
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 10 minutes
                10m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.