General developer forum

moodle 2.1 draftfile.php

Picture of Stephen Catton
moodle 2.1 draftfile.php

we are experiencing issues with a number of our moodles, where initial icons/pictures are being uploaded and then the icons disappear but the initial file missing icon appear in place of the icon. on investigation the icons url has a draftfile.php inside the details.

this seems to be trying to move the icons to another area but not renaming the url.

this is causing us a big error.

Average of ratings: -
Picture of Ian Miller
Re: moodle 2.1 draftfile.php

i’m having exactly the same problem. is this a bug?


it’s pretty strange. some files work fine, some ‘dissapear’.


edit: there’s another thread and a tracker for that





Average of ratings: -
Picture of Astrid Davine
Re: moodle 2.1 draftfile.php

A colleague is having a similar issue, with adding a 'Page'.

Within the HTML 'Page' there are icons and links to audio/narrated lecture notes/pdf files.

When hovering over and clicking on the links (in a saved page) I can see they are a 'plugin.php' type link, but when we go into the HTML source of this page, they are 'draftfile.php' type links.  This means the source cannot be used as a template for other pages by simply coping and pasting into another page.  As soon as the HTML source is copied into another page, the links become 'brokenfile.php'.

I understand that the 'plugin.php' links are the ones we need to use - but how do we access them correctly, as they never exist in the HTML source?

Actually, something that might help us in this situation, is knowing how moodle numbers files added.  I can see the files I need in the 'Server files' but don't know how to reference them properly.

Any advice (so that pages don't have to be created manually each time, but rather can be easily copied via the HTML source)?

PS. Our organisation is using Moodle 2.0.

Average of ratings: -
Picture of Stefan Nychka
Re: moodle 2.1 draftfile.php

Hi.  Use a Legacy Course Files area, or use the duplicate icon, or create a File or Folder and link to that module.

  • Duplicate's in 2.1 (your subj.) but not 2.0 (your P.S.)
  • Be careful about linking to a file within a File or Folder.
    In older versions, they at least broke across a backup/restore.

There probably is a rhyme-and-reason for how the URLs when editing are generated, and how they correspond to actual URLs, the ones you see when not editing, but I don't know it, and it may be fairly complex.  They're meant, as far as I can tell, to be local to that file, when you link and upload while editing via the File Picker.


Average of ratings: -
Picture of Pesh Kap
Re: moodle 2.1 draftfile.php

hi, I've been fighting this problem for a while now.

after some serious digging, I realized that the filepicker wasn't returning the full url, only the relative one.

So I made this change to filelib.php approximately line 752, begining of function "file_rewrite_urls_to_pluginfile", you'll see  $wwwroot = $CFG->wwwroot;

I changed it to

    $wwwroot = parse_url($CFG->wwwroot,PHP_URL_PATH);
    $text = str_ireplace("$CFG->wwwroot", "$wwwroot", $text);

And now the function and my images/files show up as they should.

Let me know if this helped any of you out, or if there is a better way to achieve what my fix did!


Average of ratings: Useful (4)
Picture of Wolfgang Stettler
Re: moodle 2.1 draftfile.php

Hi Pesh

We had this problem too on Moodle 2.2. The fix did work, thank you. Is there a tracker-issue for this problem so it will be solved in future releases?



Average of ratings: -
Picture of Humberto Saback
Re: moodle 2.1 draftfile.php

Same problem, after I applied the "fix" it fix the path but duplicated the URL, example

www . a . com (without the spaces)

Before the patch:
https://www . a . com/draftfile.php/241/user/draft/image.jpg

After the patch: https://www . a . comhttps//www . a . com/pluginfile.php/352/course/summary/image.jpg

Any idea?


Average of ratings: -
Picture of Ryan-Neal Mes
Re: moodle 2.1 draftfile.php

Did you ever come right with this?

Average of ratings: -
Picture of Shannon Wedge
Re: moodle 2.1 draftfile.php

Nope. This issue still exists in Moodle 2.9.3. What a pain.

Average of ratings: -