I did some reading and found on mysql.com MySQL :: MySQL 5.0 Reference Manual :: B.5.2.9 MySQL server has gone away
it gives you lots of possibilities why you get such an error..
You can also get these errors if you send a query to the server that is incorrect or too large. If you need big queries (for example, if you are working with big BLOB columns), you can increase the query limit by setting the server's max_allowed_packet variable, which has a default value of 1MB. You may also need to increase the maximum packet size on the client end.
there are big blobs here.. more than 300 of them
and the script loads them all into memory.. (as the images are stored in database). All depends how much memory is allocated to php.. but i think php would loose connection if it is out of mem..
I would try to move the album pictures to filesystem..
and then try to import