I'm not sure what you are doing here. If your "gallery"" is run by scripts, have you placed these scripts in the directory that is "outside" the web domain folder? If so, how do you "add" images to the directory (in other words, how do you reach the "gallery" program?) Or, is the "gallery" just a collection of images? It makes a difference, as the nix permissions on Dreamhost allow (by default) only *one user to "own" a directory; without going through some machinations by creating "groups" and using unacceptably insecure permissions, other users will not be able to "share" access to the folder in any meaningful way - they will all have to login as a single user. Additionally, you'll have "mess" with permission and symlinks, and "lions and tigers, and bears, Oh, my!" trying to serve stuff from such a directory to the web.
I could probably tell more if I knew what gallery program you are using, or if it is just an image collection, or other details as to how you are retrieving the images for web display. As it is, I can't fathom what you are trying to do.
There seems to be a good deal of misunderstanding evidenced in these statements. Firstly, "users" on Dreamhost can either be given ftp only access, mail only access, MySQL access, or full "shell" access. You establish all this when you create the user from the web panel. You probably should review the Dreamhost Wiki information on users to get a better understanding of all this.
If you create a user from the Manage Users panel section, you can decide whether they have ftp only or full shell access via a radio button (you can change this by "editing" the user from the same Manage Users" screen at any time). CGI runs under suEXEC on Dreamhost, and therefore is tied to a given "user", with whose permissions the CGI operates, but CGI is only relevant when discussing a directory that is used as, or within, a domain indicated as being "hosted" - and you identify which user CGI will run "as", as well as which version of PHP will be used from the "Manage Domains" section of the panel. Outside that context, "CGI" has no meaning for a "folder".
As for the PHP4/PHP5 and scandir(), you can "set" any domain (not user!) to use PHP4 or PHP5 at any time by using the Manage Domains screen in the Control Panel. Just click the "Edit" link to the right of the displayed domain name, modify the presented screen appropriately by selecting the radio button for the version of PHP your desire, and submitting the edited page. This is same way you can select/modify which user the CGI will run as for the domain.
In short, "CGI", or "php version" is not determined by "folder", but by the hosted domain (which, of course, is tied to a directory). Just like "all shell users are ftp users, but not all ftp users are shell users", all domains are housed in a directory (folder), but not all "folders (directories) are "domains" - and PHP usage, and CGI operation is controlled by domain, not by "folder" (directory).
Did that help at all, are you you now even more confused?