send file to browser via php - problem with IE

Discussion in 'PHP' started by falcondriver, Nov 28, 2007.

  1. #1
    hi,

    im creating a file on the fly (can be text, tiff, jpg, pdf, pretty much everything).
    now i want to send this file to the browser, instead of saving it somewhere on my server and just print out the link to this file - i dont wanna let the user know the file location.

    my code looks like this:
    (resources.php)
    
    //generate file here
    //save properties like name, size and real path in $my_file
    
    if(isset($my_file)) {
    	//$filetype = mime_content_type($my_file['path_real']);
        header('Content-Length: '. filesize($my_file['path_real']));
        if (in_array($extension, array('jpg', 'jpe', 'jpeg', 'gif', 'png')))
    	{
    		header("Content-disposition: inline; ".$my_file['name']);
    		header('Content-transfer-encoding: binary');
    	}
    	else
    	{
    		// force files to be downloaded because of a possible XSS issue in IE
    		header('Content-Disposition: attachment; filename='.$my_file['name']);
    	}
    	header('Content-type: application/octet-stream');
    	readfile($my_file['path_real']);
    }
    else {
    	header("HTTP/1.0 404 Not Found");
    }
    PHP:
    this works fine in FF and in my IE, but on other peoples IE i get an error:
    IE cannot download resources.php from mysite.com.
    any idea how to do this...?
     
    falcondriver, Nov 28, 2007 IP