You are here: Re: Using readfile to bring a "save as" dialog box up « All PHP « IT news, forums, messages
Re: Using readfile to bring a "save as" dialog box up

Posted by NC on 05/05/06 21:11

vamichael@gmail.com wrote:
>
> I'm using the following to try and send a file to user, however instead
> of getting a "save as" dialog box I'm getting ascii garbage (presumably
> the contents of the file) in the browser instead. Can someone please
> help? I need the solution to work in both Firefox and IE. Thanks!
>
> <?php
> $url="myfile.exe";
> header("Content-type: application/octet-stream");
> header("Content-Disposition: inline; filename=".basename($url)."");
> readfile($url);
> ?>

OK... There's an ugly hack that actually works...

First of all, change the URL you use to refer to your script. Right
now, you have something like this:

http://www.example.com/path/download.php

Replace it with:

http://www.example.com/path/download.php/myfile.exe

Then, you can rewrite your download.php as follows:

<?php
$url = 'myfile.exe';
header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment; filename=$url");
readfile($url);
?>

Cheers,
NC

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация