I've got a quite simple file known as openfile.php that sets a content-disposition and forces a browser to download a particular file.

It really works fine in FF, however in Safari, it downloads an unusual .xhtml file that on closer examination, seems to become the default error page that will occur.

In IE, you're just forwarded to this error page.

Can anybody deduce what's going on here?

This is a link : http://hqinternetsolutions.com/Websites/Fabric%20Traditions/?page_id=215

This is actually the code that opens the file

if ( ! isset($_GET['file']) )

if ( strpos( $_GET['file'], (isset($_SERVER['HTTPS']) ? 'https|' : 'http|') . $_SERVER['SERVER_NAME'] ) === false )

$mime = new mimetype();

$fPath = str_replace('http|', 'http://', $_GET['file']);
$fPath = str_replace('https|', 'https://', $fPath);
$fType = $mime->getType( $fPath );
$fName = basename($fPath);

$origname = preg_replace('/_#_#\d*/','',$fName);

$fContent = fetch_content( $fPath );

output_content( $fContent, $origname );

function fetch_content( $url ) {
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $url );
    curl_setopt( $ch, CURLOPT_HEADER, 0 );


    curl_exec( $ch );
    curl_close( $ch );

    $fContent = ob_get_contents();


    return $fContent;

function output_content( $content, $name ) {
    header( "Expires: Wed, 9 Nov 1983 05:00:00 GMT" );
    header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
    header( "Content-Disposition: attachment; filename=" . $name );
    header( "Content-type: application/octet-stream" );
    header( "Content-Transfer-Encoding: binary" );

    echo $content;

Your header is

Content-Disposition: attachment; filename=Pillow1.pdf

but it ought to be

Content-Disposition: attachment; filename="Pillow1.pdf"

Unsure if this sounds like the issue, when i avoid using home windows.

The hyperlink does not work with me even just in Opera, this content that get's downloaded is a few HTML page.

Searching in the headers you're delivering (http://redbot.org/?uri=http%3A%2F%2Fhqinternetsolutions.com%2FWebsites%2FFabric%2520Traditions%2Fwp-content%2Fplugins%2Fwp-publication-archive%2Fincludes%2Fopenfile.php%3Ffile%3Dhttp|hqinternetsolutions.com%2FWebsites%2FFabric%2520Traditions%2Fwp-content%2Fuploads%2F2011%2F12%2FPillow1.pdf) I note:

  • the Expires header is damaged
  • there's no Content-Transfer-Encoding in HTTP
  • Content-Type ought to be the type for PDF

(but none of them of those explain why the incorrect submissions are sent)

The main reason this PHP won't jobs are due to the %20 within the URL. You cannot have spaces or it causes the delimiter finder within the script to fail.