Cyberwizzard.nl

Welcome to my world

Debugging upload problems on JoomGallery

After installing JoomGallery and writing a migration script to migrate from Menalto Gallery2 (G2) , I finally got to uploading photos. But for some mysterious reason, every attempt to upload images would fail.

The manual upload did not work (blank page), the FTP upload did not work (blank page), the batch upload did not work (blank page or session timeout sending me back to the login) and the Java upload did not work either: 

wjhk.jupload2.exception.JUploadExceptionUploadFailed: wjhk.jupload2.policies.PictureUploadPolicy.checkUploadSuccess(): The string "JOOMGALLERYUPLOADSUCCESS" was not found in the response body

After poking around in the code for a bit I found out that the core of each upload is found in the class 'admin.upload.php' and that even with debugging enabled, zero output was shown. Even worse, looking at the Java upload handler, it became obvious that the error about "JOOMGALLERYUPLOADSUCCESS" not being found is simply not possible unless the script got terminated before it actually was done. Because I read stories about missing libraries and out of memory problems I decided to cook up a logging class to monitor the uploads to determine exactly where the script would stall.


Download the files linked below this article (make sure you are running the same version of JoomGallery or you might run into trouble) and put them in 'administrator/components/com_joomgallery/adminclasses/' and make sure the directory is writable to the httpd user (if you don't like the idea of giving Apache write permissions on the whole directory, as an alternative, you could create a file called 'debug.log', change the owner to the httpd user and chmod it to 775 so the logging function will not have to create it itself).

Now fire up the Java uploaded and try to upload a batch of photos - it should fail as before. Only this time, grab the debug.log file from that folder (http or ftp will do) and look where the script stopped.

If you are having memory problems, you will most likely have a last line saying "Creating thumnail" or "Resizing image" or similar. If that is the case, PHP ran out of memory while attempting to resize the image and it died. Read on for ideas how to fix this. Also, read up to see exactly how much memory PHP has available and how much is probably needed - in this case, the guess is wrong and the 'spare' memory is not enough to keep going. In my case, the script had 16MB to work with and guessed it needed 13MB to resize the photo - it guessed wrong...

If you have a different line ending the log, I suggest you open up the 'admin.upload.class.php' file and try to hunt down the exact function that killed your upload. Use the function lines in the logs to determine the correct function (some logging messages appear multiple times in that class). After you figure out what was going wrong, you can try to fix it - or drop me or the JoomGallery devs a note ^^

Files:
JoomGallery Upload logging class Version:1.0

Logging class for JoomGallery 1.5.0.x to debug uploads. Place this file in 'administrator/components/com_joomgallery/adminclasses/' and replace the 'admin.upload.class.php' file in that directory by the modified version to enable logging.

License GNU/GPL Date 2009-06-01 Language  English Filesize 3.08 KB Download 1387
JoomGallery modified upload class Version:1.5.0.1

Modified uploading handler class to enable logging during uploads to JoomGallery 1.5.0.1. Replace the file in 'administrator/components/com_joomgallery/adminclasses/' and make sure to download 'admin.log.class.php' as well to enable logging.

License GNU/GPL Date 2009-06-01 Language  English Filesize 53.16 KB Download 1524


In the following section, I will assume that you are using a web host running a version of Apache to serve the pages. If your server is using a different software suite (LightHTTPd or IIS for example), the names of the variables will remain the same but the place where you set them will be different.

If you indeed had a memory issue, you could try increasing the PHP limits for your webserver. Most people will not be able to edit the Apache or PHP configuration files themselves so you should edit the .htaccess file in your Joomla root folder.

After opening up .htaccess you should add the 'memory_limit' variable, if you have problems uploading photos because the upload buffer is very small, add the other 2 lines as well:

# Allow uploading images or archives up to 128MB in size - modern cameras create images of 10MB or more making a large upload buffer required
php_value upload_max_filesize 128M
# Increase the HTTP POST buffer as well as it should be able to hold the files that are uploaded
php_value post_max_size 130M
# 64MB should allow the manipulation of 15 megapixel photos or more - most hosts use 16 or 32MB default which is not enough
php_value memory_limit 64M


Do not forget to revert to the default JoomGallery upload class or to disable logging by default - otherwise the log file will grow each time you upload something and other people might be able to see exactly which files you have in your gallery. To do this, open up 'admin.log.class.php' and replace on line 20 'd_all' with 'd_none'. Now remove the 'debug.log' file and unless you enable the debug mode from the upload page somewhere, you won't see a new log file when you upload something.

JoomGallery Upload logging class Version:1.0

Logging class for JoomGallery 1.5.0.x to debug uploads. Place this file in 'administrator/components/com_joomgallery/adminclasses/' and replace the 'admin.upload.class.php' file in that directory by the modified version to enable logging.

License GNU/GPL Date 2009-06-01 Language  English Filesize 3.08 KB Download 1387
JoomGallery modified upload class Version:1.5.0.1

Modified uploading handler class to enable logging during uploads to JoomGallery 1.5.0.1. Replace the file in 'administrator/components/com_joomgallery/adminclasses/' and make sure to download 'admin.log.class.php' as well to enable logging.

License GNU/GPL Date 2009-06-01 Language  English Filesize 53.16 KB Download 1524