March 4, 2014
ExpressionEngine, Wygwam, CKFinder and MediaTemple problems…
I recently got bitten by a nasty problem on an ExpressionEngine site hosted at MediaTemple. All of a sudden they weren’t able to upload images to a Wygwam field using the CKFinder setting for the File Browser. The error message stated:
The file browser is disabled for security reasons. Please contact your system administrator and check the CKFinder configuration file.
Not exactly a helpful error message and definitely not the right solution. I went down the rabbit hole trying to sort this one out and it all comes down to how Wygwam figures out the path it should upload your file to when you use CKFinder as your file browser tool.
It does appear to be isolated to MediaTemple servers for some reason, but I am not entirely sure why.
So first, a little information about how Wygwam determines where to put your file. Wygwam depends on PHP session variables to know which folders in your file system are available to upload to for any given field. PHP creates a PHPSESSID cookie which matches a file saved to the server in your PHP session directory. Within that file are all the relevant details about the upload folders. When Wygwam goes to upload a file, it checks the session for the logged in user and figures out where to put the files.
My problem was due to the session data file being created on the server, but never being updated. The file was blank, so when Wygwam went to check for the directories it should have access to, it found a blank file and assumed that there weren’t any files to upload to, which leads to the error.
So why was the file blank?
This took some digging, but I was able to solve the problem by removing a single line of code in a Wygwam file. Specifically /system/expressionengine/third_party/wygwam/helper.php. In version 3.3.2 of Wygwam, the line in question is 675:
if (! isset($_SESSION)) @session_start();
This seems like a reasonable conditional, if the $_SESSION superglobal isn’t set, let’s create a session. However, it just doesn’t work on the MediaTemple server this site is on. The $_SESSION IS set at this point, but there isn’t anything in it. For whatever reason, on this server, the @session_start() call NEEDS to happen here or the rest of the script in helper.php will fail. So by changing line 675 to
All is well.
I’m not enough of a server admin to know exactly why this would be, but I’m pretty sure it has to be related to some configuration on the MediaTemple side of things. I’d love to know why this is so if anyone has a server side solution instead of changing the code, please leave it in the comments below!
For what it’s worth. This error is present on:
- ExpressionEngine 2.9.2
- Wygwam 3.3.2
- MediaTemple (gs) Grid-Service (PHP 5.3.29 CGI)