in reply to Passing variable from one cgi to another
You could, instead of having two cgi files, create a module that works the images and in your main cgi you simply call that module's methods.
One of them would return you the name of the file. And then your main.cgi does the print with the image name already there.