Re: File Open Prompt?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



----- Original Message ----- 
From: "Ashley Sheridan" <ash@xxxxxxxxxxxxxxxxxxxx>
To: "Dan Shirah" <mrsquash2@xxxxxxxxx>
Cc: "PHP General" <php-general@xxxxxxxxxxxxx>
Sent: Saturday, August 29, 2009 3:10 AM
Subject: Re:  File Open Prompt?


> On Fri, 2009-08-28 at 15:03 -0400, Dan Shirah wrote:
> 
>> Greetings,
>> 
>> I'm having a problem trying to get a file download prompt.
>> 
>> Basically I have a page with image links.
>> 
>> When the link is clicked, the user is directed to another page I have. That
>> page finds the image path based on the image ID from the previous page.
>> 
>> Once the image path is found I copy the image to the local webserver and
>> rename the proprietary extension, .0D9 to .tif
>> 
>> Once the file is renamed to .tif I want the download prompt to come up.  You
>> know, where it says, "Open" "Save" "Cancel".
>> 
>> I've tried using:
>> 
>> $fp = fopen($new_file,"r") ;
>> header("Content-Type: image/tif");
>> while (! feof($fp)) {
>>        $buff = fread($fp,filesize($new_file));
>>        print $buff;
>>        }
>> 
>> But that just gives me heiroglyphics on the screen instead of prompting the
>> user to download.
>> 
>> Here is my code that copies and renames the file:
>> 
>> if ($page != "" || $page != " ") {
>>  exec("xcopy ".$page." ".$topage."");
>> }
>> $orig_file = $topage."\\".$objectid.".0D9";
>> //echo $orig_file;
>> $new_file = $topage."\\".$objectid.".tif";
>> //echo $new_file;
>> 
>> rename($orig_file,$new_file);
>> 


You will need to add some headers to the page to popup the prompt, at least with 
these.

$filename = 'somefile.tif';
$filesize = filesize($filename);

header('Content-Type: application/force-download');
header('Content-disposition: attachement; filename=' . $filename);
header('Content-length: ' . $filesize);

Eric

>> Any ideas on how to make the browser give the download prompt for $new_file?
>> 
>> Thanks,
>> Dan
> 
> You need to send down the right headers to the browser, so that it knows
> it's meant to save the file, and not attempt to display it. If the link
> was to a file, you'd have certain header that informed the browser the
> mime type of the file.
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 
>


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux