I think you mean to echo it into the hyperlink href <a href="<?php echo "$filePath$img"; ?>" class="galpop" data-galpop-group="gallery"> but your description is confusing because both methods use PHP...