Support » Plugin: NextGEN Gallery - WordPress Gallery Plugin » When uploading pics "An unexpected error occured"

  • Resolved Tiberun



    When I try to upload images into NextGen, it stops at different procentages and then after a while I get this error message:

    An unexpected error occured. This is most likely due to a server misconfiguration. Check your PHP error log or ask your hosting provider for assistance.
    0 images were uploaded

    However, when I look in the gallery the picture has been uploaded, but only the first picture if I do bulk uploads.
    It started to occur at the same time as I changes host for my WP blog. That made me believe it was something wrong with the new host so I contacted 2nd line support and they looked into the issue. They see no error on the server side, al they get is a timeout string as this:

    [Tue Jan 14 16:43:41 2014] [warn] [client] Timeout waiting for output from CGI script /usr/bin/php-cgi
    [Tue Jan 14 16:43:41 2014] [error] [client] Premature end of script headers: php-cgi
    [Tue Jan 14 16:48:41 2014] [warn] [client] Timeout waiting for output from CGI script /usr/bin/php-cgi

    The timeout setting for the php installation is set quite high so shouldn’t be the problem:

    max_execution_time = 1600

    The files I’m trying to upload is normal jpeg’s between 200k and 2Mb so should not timeout.

    I have turned on debug on WP but can not see anything there related to this.
    The host has other WP customers and none of them have reported this issue.
    At the same time, might not be related to the same error, plug-in and core updates also stop in the progressbar and finally time out as the upload for the images do. When I check all the updates were still performed.

    I have searched the web and looked through your support forum but I can not find a fix for this, please help.

Viewing 15 replies - 1 through 15 (of 17 total)
  • Checked the debug-file after I tried to upload a picture and this is what I get:

    [22-Jan-2014 20:23:43] PHP Notice: ob_end_clean(): failed to delete buffer zlib output compression. in / on line 35

    Hello again,

    Just finished a talk with the 2nd line support. He was editing the code in /wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/ajax/class.ajax_controller.php

    He explained it that if zlib compression is turned off on the webserver you need to set a parameter to ob_start and make sure that ob_end_clean is full before it is cleared with ob_get_level otherwise it will try to clear an empty buffer which will result in the failed to delete zlib buffer etc.

    This is the edit he made and now it works:

    //crystone fix
            if( substr_count( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) )
    //crystone fix
            //while (ob_get_level() > 0) {
            while(ob_get_level() > 1) {


    Wonderful, I had the same problem and your hack could solve it! Wonder if they’ll fix this in a future release of the plugin.



    Tiberun, I have edited class.ajax_controller.php but error is not gone. Are there any other options for me?



    I have found out that Adblock Plus – a Firefox addon is messing with Nextgen Gallry. Turn it off and gallery works, more or less…

    Plugin Author photocrati


    @losmi – Thanks for the follow-up!

    – Cais.

    Hello team,
    I got the same error msg :
    An unexpected error occured. This is most likely due to a server misconfiguration. Check your PHP error log or ask your hosting provider for assistance.
    I looked into PHP error log and found no error. I looked in the Gallery and I found all pictures are inside. so the upload is fine and I just get this error msg. or…

    it bothers/confuses me that I got this error msg. could you please post corrected/Edited “class.ajax_controller.php”. I am not sure how to edit this PHP file.

    thank you

    Plugin Author photocrati

    (@photocrati) – It would probably be best for you to create your own topic as I suspect the circumstances for your site are different than the OP.

    See this for more details:


    – Cais.

    Cais. sure. thank you!

    I tried the class.ajax_controller.php fix. It gets rid of the error message but I’m still not able to upload more than 1 file at a time.

    I also talked to Hostgator support and they told me it’s not a server issue.

    Any other ideas on what I could try? thanks

    Plugin Author photocrati


    Hmmm, unlikely. Most upload issues are corrected by resetting permalinks to ‘post name’ under settings > permalinks, increasing your server /wp-content file permissions to 755 or upgrading/increasing server settings. Would you mind copying and pasting your server settings found under Gallery > Overview ? thanks!


    My permalinks structure is /%category%/%postname%/ for SEO purposes but I’ve never had an issue before a week ago. Are you saying to click on Post Name, then go back to my current setting?

    Here are the current server settings. Hostgator told me they have increased everything.

    Operating System : Linux (64 Bit)
    Server : Apache
    Memory usage : 37.44 MByte
    MYSQL Version : 5.5.40-36.1
    SQL Mode : Not set
    PHP Version : 5.3.28
    PHP Safe Mode : Off
    PHP Allow URL fopen : On
    PHP Memory Limit : 256
    PHP Max Upload Size : 64M
    PHP Max Post Size : 64M
    PCRE Backtracking Limit : 1000000
    PHP Max Script Execute Time : 30s
    PHP Exif support : Yes ( V1.4 )
    PHP IPTC support : Yes
    PHP XML support : Yes

    Graphic Library

    GD Version : bundled (2.1.0 compatible)
    FreeType Support : Yes
    FreeType Linkage : with freetype
    T1Lib Support : No
    GIF Read Support : Yes
    GIF Create Support : Yes
    JPEG Support : Yes
    PNG Support : Yes
    WBMP Support : Yes
    XPM Support : No
    XBM Support : Yes
    JIS-mapped Japanese Font Support : No


    Plugin Author photocrati


    @mimulka — Hmm, those settings appear to be OK. Your permalink settings, I have the same on my own site but mine do not have the / at the end. try changing yours to:


    does that help?

    @photocrati No unfortunately still the same issue only one file uploads. Also since I changed the class.ajax_controller.php file, it only shows one picture loading but doesn’t show the rest of the process. It’s like it’s stuck.

    Plugin Author photocrati


    @mimulka – You changed the class.ajax_controller.php file? Could you rollback your changes and see if that helps?


Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘When uploading pics "An unexpected error occured"’ is closed to new replies.