You could possibly do this test in the other one within a loop? They look identical except for a couple variables (filename and content_type)