It is one of 2 things:
1. When you go there directly there, no $_GET is established. $_GET['p'] will probably be equal to NULL, NOT "" and therefore it goes through your final else statement that outputs no image.
Or 2. If the code above is correct, you have 2 elseif statements for $_GET['p'] = "" and the first one doesn't do anything and will be the only one that fires. Remove it and the above code might work...