Moodle

"Show directory" resource bug

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: 1.9.1
  • Fix Version/s: None
  • Component/s: Resource
  • Labels:
    None
  • Environment:
    SUSE LAMP

Description

When using the "display a directory" resource, files with spaces in them do not work. A "Sorry, the requested file could not be found" is displayed instead.

I am sure this has not always been the case.

When linking to this files directly using the "link to file or website" resource underscores are put in automatically and the resource displays.

Activity

Hide
Nadav Kavalerchik added a comment -

this happens only when uploading a zip file and letting moodle open it as if it is a folder.

actually, i think it opens temporarily and you can not link to it permanently ?

it does not happen when loading normal files (from the local computer) which have spaces inside the file names !
(they get underscores , automatically)

Show
Nadav Kavalerchik added a comment - this happens only when uploading a zip file and letting moodle open it as if it is a folder. actually, i think it opens temporarily and you can not link to it permanently ? it does not happen when loading normal files (from the local computer) which have spaces inside the file names ! (they get underscores , automatically)
Hide
Charlie Owen (SonniesEdge) added a comment -

We've encountered similar problems since upgrading to 1.9. Files can't be found via the directory resource, but can be accessed via the course file management screen.

Ubunutu 7.10 LAMP

Show
Charlie Owen (SonniesEdge) added a comment - We've encountered similar problems since upgrading to 1.9. Files can't be found via the directory resource, but can be accessed via the course file management screen. Ubunutu 7.10 LAMP
Hide
Charlie Owen (SonniesEdge) added a comment -

To replicate this problem upload a bunch of files to your course, all with spaces in their filenames and zipped together inside a single ZIP file. Create a directory, unzip the files to that directory and then use the "Display a directory" resource to show those files. All files with spaces will generate an error of "Sorry, the requested file could not be found". Files without spaces in the filename display correctly.

Show
Charlie Owen (SonniesEdge) added a comment - To replicate this problem upload a bunch of files to your course, all with spaces in their filenames and zipped together inside a single ZIP file. Create a directory, unzip the files to that directory and then use the "Display a directory" resource to show those files. All files with spaces will generate an error of "Sorry, the requested file could not be found". Files without spaces in the filename display correctly.
Hide
Charlie Owen (SonniesEdge) added a comment -

Okay, this is weird. Even after manually replacing spaces with underscores via the OS, those files uploaded via a zip file still cannot be found by the directory resource module.

Show
Charlie Owen (SonniesEdge) added a comment - Okay, this is weird. Even after manually replacing spaces with underscores via the OS, those files uploaded via a zip file still cannot be found by the directory resource module.
Hide
Samuli Karevaara added a comment -

Using 1.9.1+ and Firefox 2 I couldn't replicate this. I had two files with spaces in their names in a folder with also a space in its name. I zipped the folder, uploaded to Moodle, unpacked via Moodle. Both linking directly and with the "Display a directory" resource worked. What else might be in play here?

Show
Samuli Karevaara added a comment - Using 1.9.1+ and Firefox 2 I couldn't replicate this. I had two files with spaces in their names in a folder with also a space in its name. I zipped the folder, uploaded to Moodle, unpacked via Moodle. Both linking directly and with the "Display a directory" resource worked. What else might be in play here?
Hide
Charlie Owen (SonniesEdge) added a comment -

Sorry for slow reporting on this - trying to get some work done at the same time! Just looked at the URLs that are being requested by the browser.

These are examples of files with spaces in the filename, that have been uploaded individually:
http://<moodleroot>/file.php/2/wordtest_individualuploads/New_Microsoft_Word_Document.doc
http://<moodleroot>/file.php/2/wordtest_individualuploads/Unit_13_Knowledge_Questions.doc

The same files, but uploaded via a zip file:
http://<moodleroot>/file.php/2/wordtest_zippeduploads/New+Microsoft+Word+Document.doc
http://<moodleroot>/file.php/2/wordtest_zippeduploads/Unit+13+Knowledge+Questions.doc

The first group of examples work, while the second don't.

Show
Charlie Owen (SonniesEdge) added a comment - Sorry for slow reporting on this - trying to get some work done at the same time! Just looked at the URLs that are being requested by the browser. These are examples of files with spaces in the filename, that have been uploaded individually: http://<moodleroot>/file.php/2/wordtest_individualuploads/New_Microsoft_Word_Document.doc http://<moodleroot>/file.php/2/wordtest_individualuploads/Unit_13_Knowledge_Questions.doc The same files, but uploaded via a zip file: http://<moodleroot>/file.php/2/wordtest_zippeduploads/New+Microsoft+Word+Document.doc http://<moodleroot>/file.php/2/wordtest_zippeduploads/Unit+13+Knowledge+Questions.doc The first group of examples work, while the second don't.
Hide
Marcius Herbert added a comment -

It appears to be a problem with unzipped directories that contain spaces, PHP/Moodle replaces the spaces with + making the complete path incorrect.

While not ideal, a temporary fix was to add the following line of code in the function 'get_file_url' found in \lib\filelib at line 16/17 (fix surrounded by comments //MHE )

if ($CFG->slasharguments) {
//MHE
$path = str_replace(" ", "%20",$path);
//MHE

this stops the function replacing spaces with +s

Hope this helps

Marcius Herbert
Sutton Coldfield College
UK

Show
Marcius Herbert added a comment - It appears to be a problem with unzipped directories that contain spaces, PHP/Moodle replaces the spaces with + making the complete path incorrect. While not ideal, a temporary fix was to add the following line of code in the function 'get_file_url' found in \lib\filelib at line 16/17 (fix surrounded by comments //MHE ) if ($CFG->slasharguments) { //MHE $path = str_replace(" ", "%20",$path); //MHE this stops the function replacing spaces with +s Hope this helps Marcius Herbert Sutton Coldfield College UK
Hide
Charlie Owen (SonniesEdge) added a comment -

I can confirm that the temp fix by Marcius works for us. Thanks!

Show
Charlie Owen (SonniesEdge) added a comment - I can confirm that the temp fix by Marcius works for us. Thanks!
Hide
Julian Ridden added a comment -

I can also confirm fix worked for us

Show
Julian Ridden added a comment - I can also confirm fix worked for us
Hide
Martin Dougiamas added a comment -

Note: Spaces in file names are not supported officially in Moodle < 2.0 (same with wierd UTF names). (both are being fixed once and for all in Moodle 2.0 with all the new file API).

This patch fixes this one issue but I suspect won't fix all of the issues with spaces. But I'll get it in CVS for 1.9.2 anyway. Thanks!

Show
Martin Dougiamas added a comment - Note: Spaces in file names are not supported officially in Moodle < 2.0 (same with wierd UTF names). (both are being fixed once and for all in Moodle 2.0 with all the new file API). This patch fixes this one issue but I suspect won't fix all of the issues with spaces. But I'll get it in CVS for 1.9.2 anyway. Thanks!
Hide
Paul Taylor added a comment -

I used the fix from Marcius on a 1.8.8 site and it worked fine, in that uploaded zips with files with spaces worked correctly. However, if you then use that unzipped folder as a linked directory on the course (as martin suspects above), the + signs re-appear and the links do not work again. Does anyone know what php file controls how these links are stored in the database? I assume it is not the same filelib.php file, or is it somewhere else in that file.

Show
Paul Taylor added a comment - I used the fix from Marcius on a 1.8.8 site and it worked fine, in that uploaded zips with files with spaces worked correctly. However, if you then use that unzipped folder as a linked directory on the course (as martin suspects above), the + signs re-appear and the links do not work again. Does anyone know what php file controls how these links are stored in the database? I assume it is not the same filelib.php file, or is it somewhere else in that file.
Hide
Petr Škoda (skodak) added a comment -

the problem is more probably a simple bug, missing urlencode

Show
Petr Škoda (skodak) added a comment - the problem is more probably a simple bug, missing urlencode
Hide
Michael de Raadt added a comment -

Thanks for reporting this issue.

We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported.

If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed.

Michael d;

lqjjLKA0p6

Show
Michael de Raadt added a comment - Thanks for reporting this issue. We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported. If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed. Michael d; lqjjLKA0p6
Hide
Michael de Raadt added a comment -

I'm closing this issue as it appears to have become inactive and is probably not relevant to a current supported version. If you are encountering this problem or one similar, please launch a new issue.

Show
Michael de Raadt added a comment - I'm closing this issue as it appears to have become inactive and is probably not relevant to a current supported version. If you are encountering this problem or one similar, please launch a new issue.

Dates

  • Created:
    Updated:
    Resolved: