<pre>$parsed = parse_url( wp_get_attachment_url( $attachment->ID ) ); $url = dirname( $parsed [ 'path' ] ) . '/' . rawurlencode( basename( $parsed[ 'path' ] ) );</pre> <pre>