Symbolic link if file doesn't exist - is this possible

I’m setting up a test subdomain on my server to test changes. I’ll be copying over the php files from my main site. However there’s a lot of pictures (product pictures, mostly) on the site so I don’t want to just copy them over and hog hard drive space. I could just symbolic link the images directory to the images directory on the live site (they’re on the same server) however some of the things I might be testing are filesystem changes to files in the images directory (creating, deleting, edit images etc) that I don’t want reflected on the live site.

I could use mod rewrite to check if an image exists and, if it doesn’t, serve the appropriate image from the main site (at least I think that’s possible), but if it’s doing that with a lot of pictures on the page I reckon this would be really slow, and it also doesn’t help me with file system access to the files (eg accessing image dimensions via php for example).

Is what I’m asking for do-able? Is a mass copy of the image directory a more accepted solution?


-l is the if symbolic link shortcut but that’s not what you’re after. -f will test the {REQUEST_FILENAME} to see if it exists as a file then you’ll need to run your link in the redirection.

IMHO, the cleaner way should be to either copy all the files (actually, just the ones you want to play with) OR link to them with an external link (if not in the same domain’s webspace).