How to get attachment file name not attachment URL
I would strongly advise against using $post->guid – WordPress now generates them in the form; http:/example.com/?attachment_id=ID Use the same method that many of the attachment-related functions use; $filename = basename ( get_attached_file( $data->ID ) );