HTTP error 0 occurred
After just spending most of the day on this and this being one of the most frustrating issues i've come across with Drupal I thought i'd write a list of fixes for this Filefield AHAH 'HTTP error 0 occured' as it may help someone else. There are lots of suggestions on Drupal.org but it takes a lot of searching to go through them all.
My setup is running Drupal 6.22 with the Seven admin theme, PHP 5.3.5, Apache running on CentOS. The image and file modules i'm using are: ImageAPI 6.x-1.10, Filefield 6.x-3.10,ImageField 6.x-3.10, Filefield Paths 6.x-1.4.
Check Your Theme Scripts
I'm putting this one first as it was the cause of the problem for me. I thought what had recently changed - I had just moved servers but had also enabled a javascript preloader on the website. The javascript for the upload field (if you view source on the page) is within the variable in your admin themes page.tpl.php. The and the variable were both contained within the head part of the document. I moved them both to before the closing body tag and then the script processed correctly and the images uploaded without the error.
<?php print $scripts; ?> <?php print $closure; ?> </body>
EDIT: This wasnt actually the problem in the end. It was the javascript preloader interfering with the Drupal AHAH script! Caching issues made it difficult to test for, oh well got there in the end :)
Disable Javascript In Your Browser and Plugins
Disabling javascript is an obvious quick fix to the problem as it then stops the javascript from even running on the page so the error is not displayed. The next step would be to disable all plugins in your browser, if that fixes the problem, enable each plugin one by one and test to see which is causing the issue. This was a problem for some people using different browsers on different OS's.
Update Your File and Image Modules
Some older versions of the filefield module had the AHAH section commented out, not sure why, but updating your modules to the most recent versions would be the first thing to check.
ImageAPI - http://drupal.org/project/imageapi
Filefield - http://drupal.org/project/filefield
Filefield Paths (probably not the problem but a handy module to have) - http://drupal.org/project/filefield_paths
Imagefield - http://drupal.org/project/imagefield
Also check that the permissions are correct on the folders and files in your sites/default/files directory.
Upgrade Jquery
Install the jquery update module to update to a newer version of Jquery - http://drupal.org/project/jquery_update. If that doesnt fix the problem then its probably best to disable this as it could cause issues elsewhere.
Check Your Upload Limits
This wasnt the cause of the problem for me but you should set this up even if you're not having problems. Setting post and upload sizes will limit the size of the file that can be uploaded which you will see when creating the image or file field in CCK. If your limit is too small, increase the post_max_size and upload_max_filesize to what you need. Increasing the memory_limit will allow for larger image processing and setting a longer max_execution_time gives scripts longer process and can fix a lot of WSOD errors.
In your php.ini add or modify:
post_max_size 2M upload_max_filesize 2M memory_limit 96M max_execution_time 120
OR if you dont have access to php.ini, In your .htaccess add:
<IfModule mod_php5.c> php_value post_max_size 2M php_value upload_max_filesize 2M php_value memory_limit 96M php_value max_execution_time 120 </IfModule>
Check FastCGI config
There's a MaxRequestLen value that can be set if you are using PHP as FastCGI in:
/etc/httpd/conf.d/fcgid.conf
You may see this has been set to 128KB, change this to something a lot higher like 15mb:
MaxRequestLen 15728640
Install ImageMagick
SSH into your server and enter the following commands to install ImageMagick to process the images instead of PHP's built in GD2. ImageMagick-6.7.2-9 is the most recent version when writing this, you may want to visit ftp://ftp.imagemagick.org/pub/ImageMagick and check for the newest version. I'll keep this as ImageMagick-6.7.2-9 as I this is what i've installed and know it works.
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-6.7.2-9.tar.gz
tar xvfz ImageMagick-6.7.2-9.tar.gz
cd ImageMagick-6.7.2-9
./configure
make
sudo make install
sudo ldconfig /usr/local/lib
make check
Then you want to go to into Drupal admin /admin/settings/imageapi and set the image toolkit as Image Magick. I also had to go to configure and set the path to the convert binary as:
/usr/local/bin/convert
I then had open_basedir errors and so had to allow PHP to access the /usr/local/bin/convert directory. Locate your websites conf folder in the virtual host folder:
var/www/vhosts/yourdomain.com/conf
Then create a file in that folder called:
vhost.conf
Add to the file:
<Directory /var/www/vhosts/yourdomain.com/httpdocs> php_admin_value open_basedir /var/www/vhosts/yourdomain.com/httpdocs/:/tmp/:/usr/local/bin/convert php_admin_value include_path /var/www/vhosts/yourdomain.com/httpdocs/:/tmp/:/usr/local/bin/convert </Directory>
Then you need to restart apache:
/etc/init.d/httpd
If you have any other solutions to this issue which doesnt fall under any of the above please post details in the comments.