quiz images not working

quiz images not working

by Andrew Lyman-Buttler -
Number of replies: 12

Hi all,

I can't get quiz images working. This problem drove me so crazy I completely uninstalled Moodle from the server and started over, but it's still happening.

Here's a screenshot. The image on top was inserted with an <img> tag. The broken link on the bottom is the one I tried inserting with the button in the text editor.

I'm seeing this behavior in other places on the site too. In some contexts (user profile image, course description files) the uploaded image works just fine, but in most others (quizzes, labels, activities) it doesn't work.

I noticed the image addresses always invoke "draftfile.php" when it fails, and if I copy and follow that image address, I get the error message "You are already logged in as ___, you need to log out before logging in as different user." Could it be some sort of permission problem?

If I write a forum post, I can't upload an image and insert it into the text of the post, but interestingly enough, I can upload it as an attachment and then it works fine. Is there a difference between the "Attachment" field and the text editor file picker? Why would one work but not the other? Could it be a server setting? I'm on Bluehost running Moodle 3.0. Is it a PHP problem?

Please help...school starts in one week, and I've tried (and failed) for countless hours to fix this on my own. Thanks in advance.

Average of ratings: -
In reply to Andrew Lyman-Buttler

Re: quiz images not working

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

When you are editing things in the HTML editor, the URL will be something involving draftfile.php. When you save, and then view the content for real (e.g. preview the quiz question) that should get converted to something involving pluginfile.php.

To go into a bit more details,x when you save, what gets saved in the database will contain @@pluginfile@@ in place of the http://your.moodle/draftfile.php bit of theURL. If you have a way to look in the database, you should be able to see this in the mdl_question table, in the questiontext column. Also, there will be one row written to the mdl_files table for each file.

Then, when the thing (e.g. question) is viewed, the @@pluginfile@@ bit gets replaced by a URL like http://your.moodle/pluginfile.php/a/whole/bunch/of/ids/.

Checking in the database will tell you if the problem is when the content is displayed or when it is viewed.

If the problem is when the thing is viewed, and if the URL looks OK, then try this:

  1. Turn on DEVELOPER Debugging
  2. Open pluginfile.php in a text editor, and 'comment out' the line near the top.
    define('NO_DEBUG_DISPLAY', true);
    That is, change it to be
    // define('NO_DEBUG_DISPLAY'true);
  3. Right-click on one of the non-working images, and do Open in new tab.
  4. See if there are any error messages.

I hope some of that work. The good news is that all images in Moodle work the same way, so when (if!) you solve this in one place, it will work everywhere.

In reply to Tim Hunt

Re: quiz images not working

by Andrew Lyman-Buttler -

Thanks so much for your quick reply. I enabled debugging in draftfile.php and pluginfile.php but when I follow the link for the broken image, the only error I get is "You are already logged in as ___, you need to log out before logging in as different user."

I am on the phone with Bluehost to see if it's a permissions/PHP/database issue of some sort, but they have no idea. It happens even on a totally clean install. Could it be some sort of database problem? I have tried to "repair database" but it says it does not support repair. Anyway, I created a brand new database for the new Moodle installation and that didn't make a difference.

If it helps, this problem started midway through the last school year, and I muddled through the rest of the year by just avoiding using any images. This summer I thought I'd try a fresh install, but the problem remains. This leads me to believe that maybe Bluehost changed something on the server side that broke Moodle's image handling. None of them seem to have any idea what that might be, though.

In reply to Andrew Lyman-Buttler

Re: quiz images not working

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

It looks like a problem with the PHP session. If you look in your browser developer tools, at the Network bit. Can you see if the same cookies are being sent with each request (the main page load, and when the images are loaded.)

In reply to Tim Hunt

Re: quiz images not working

by Andrew Lyman-Buttler -

Also, I know the images are being successfully uploaded because they are showing up (with accurate thumbnails) in the "Recent files" repository. If I try using "recent files" to insert an image, however, it still results in a broken image placeholder.

In reply to Tim Hunt

Re: quiz images not working

by Andrew Lyman-Buttler -

OK, now things are getting really weird. I inserted a broken placeholder, and went away for a while. When I came back, the placeholder was replaced with the image! I've also seen it go the opposite way a couple times; images that somehow miraculously inserted correctly have disappeared.

The Bluehost people were totally baffled by all this, and they claim it's nothing on their end.

In reply to Tim Hunt

Re: quiz images not working

by Andrew Lyman-Buttler -

One last bit of info; I opened the Moodle database in phpmyadmin and it looks like all the image files are in there, and have the same name, filesize, etc. that I'd expect. Database check says everything's OK too.

Thanks again!

In reply to Andrew Lyman-Buttler

Re: quiz images not working

by Andrew Lyman-Buttler -
I found out the hard way that it was a Bluehost issue. First I completely uninstalled Moodle and started fresh. Didn't work. Then I started over again, but this time I installed it manually instead of with the Bluehost script. Still no dice. Finally, I called Bluehost support and had them "nuke" my account, which they told me would wipe my home directory and restore all settings and configuration files to default, like creating a new account. After doing this I reinstalled Moodle AGAIN, and it still didn't work.


I just created an account on Siteground and everything seems to be working fine there.

Any idea what server-side issue on Bluehost's end might be responsible? In the meantime, I think the Moodle community should be cautioned against using them (unfortunately, as they do have really good reliability and friendly, responsive support) until they/we can figure out why image uploads aren't working.

In reply to Andrew Lyman-Buttler

Re: quiz images not working

by Rodrigo Cervantes -

Same problem. Using Bluehost Cloud Hosting Performance.

In reply to Rodrigo Cervantes

Re: quiz images not working

by Andrew Lyman-Buttler -

That's too bad. I migrated my site to Siteground and, while they are quite stingy with CPU usage and script executions, it has been working. I wouldn't recommend Siteground for an installation with more than 100 users or so.

In reply to Andrew Lyman-Buttler

Re: quiz images not working

by Rodrigo Cervantes -

Found a solution!  Disabling cache in the "Site caching" section on Bluehost's Cpanel made everything work again. Images showed up, files worked again.   Anyway, i see this as a temporary solution.  We enabled cache as one of the many tweaks recommended in various sites to improve Moodle performance.

For the time being, teachers prefer a slow but usable site.  We'll analyse if it's better to switch hosting provider or to throw more money at this one, in the form of ram and processor cores.

In reply to Rodrigo Cervantes

Re: quiz images not working

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

Rodrigo, which tool (or icon) in cPanel provides this "site cache" feature (or setting)?