He is trying to send a .php file, not a .txt file. I tried the
following script, modifying yours slightly to his actual situation,
not what you chose to read into it. Since he wants to send a .php
file, and not plain text...
<?php
// load content into var
$filecontent="<?php echo 'this is a test'; $var1=5;";
$downloadfile="somefile.php";
header("Content-disposition: attachment; filename=$downloadfile");
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".strlen($filecontent));
header("Pragma: no-cache");
header("Expires: 0");
?>
Obviously the $var1 is going to give him problems, since it's going
to try to interpret it before it sends the contents. Perhaps reading
the file into a variable?
<?php
// load content into var
$filecontent=readfile("page.php");
$downloadfile="somefile.php";
header("Content-disposition: attachment; filename=$downloadfile");
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".strlen($filecontent));
header("Pragma: no-cache");
header("Expires: 0");
?>
and page.php:
<?php
echo 'this is a test';
$var1=5;
?>
Well, now. That seems to work. You're right. Trying things out before
recommending them IS the right answer...
The answer I gave was such because there are cases where it will NOT
work, as your own example (when modified to download an actual PHP
file) showed.
But everything I've seen, heard, and coded, tells me it's not the
best idea to let someone download actual PHP code. A zip file of it?
Sure. Emailed? ok, I guess. Put into a text box so they can copy and
paste it? fine. But downloaded directly? Why?
By the way, the solution to this is the very first example under
readfile n the manual. Perhaps a bit of RTFM is in order?
Mark
--- ravi pandey <[EMAIL PROTECTED]> wrote:
> Hi Friends , I saw the discussion and think that we dont refer to
> material before helping anyone.
> pls pls dont give half or wrong information , just check it before
> you give anyhelp to anyone.
> so yogita i answered your question but when i saw the answers you
> got for your question couldnot stop this
> so pls try think , it works 100% sure.
> <?php
>
> // load content into var
>
> $filecontent="Some text/code im creating in the script";
> $downloadfile="somefile.txt";
>
> header("Content-disposition: attachment; filename=$downloadfile");
> header("Content-Type: application/force-download");
> header("Content-Transfer-Encoding: binary");
> header("Content-Length: ".strlen($filecontent));
> header("Pragma: no-cache");
> header("Expires: 0");
>
> ?>
> tell me if it works
>
>
> <[EMAIL PROTECTED]> wrote:
> All of these will either open or download the post-processed page
> (e.g. an HTML page, not the PHP code). PHP is specifically designed
> (integrated with the server) to process the PHP part of the page
> before sending anything. So no matter what you do, you cannot
> download the PHP itself except possibly by changing the link to an
> FTP, (but I don't think that will work), or streaming the PHP page
> to
> the user by sending the content-type header. Even then, it won't
> necessarily work.
>
> If it's your server, and you want to show the content of the
> script,
> use .phps rather than .php (you could even use a PHP script to
> dynamically write out a .phps file and redirect to it).
>
> If it's not your server, you shouldn't be trying to download
> someone
> elses' work. Email them and ask.
>
> Mark
>
> --- Ian Bambury <[EMAIL PROTECTED]> wrote:
>
> > Right-click | "Save target as..."
> >
> >
> > On 06/11/05, Wes G <[EMAIL PROTECTED]> wrote:
> > >
> > > Try shift click
> > >
> > > On 11/5/05, arunmohan kamalakannan <[EMAIL PROTECTED]>
> wrote:
> > > >
> > > > Hi,
> > > > Try to give full name in that href. For example:
> > > > <a
> > > > href='/home/bin/usr/member/example.php'>example.php</a>
> > > >
> > > > See the above code here we are not giving
> > > > http://www.hostname.com/member/example.php. We only
> > > > give linux folder name as above.
> > > >
> > > > Try it. I hope it works clearly.
> > > >
> > > > With regards,
> > > > Arun
> > > > With regards,
> > > > Arun
> > > > --- Yogita <[EMAIL PROTECTED]> wrote:
> > > >
> > > >
> > > > ---------------------------------
> > > > How to download file [.php] in php ?
> > > >
> > > > When we click on link.............it sould ask for
> > > > save option....i.e diaplog box.
> > > >
> > > > Not open in same browser...........
> > > >
> > > > Does anybody know ?
> > > >
> > > >
> > > >
> > > > Yogita
> > > >
> > > >
> > > > ---------------------------------
> > > > Yahoo! FareChase - Search multiple travel sites in
> > > > one click.
> > > >
> > > > [Non-text portions of this message have been removed]
> > > >
> > > >
> > > >
> > > > Community email addresses:
> > > > Post message: [email protected]
> > > > Subscribe: [EMAIL PROTECTED]
> > > > Unsubscribe: [EMAIL PROTECTED]
> > > > List owner: [EMAIL PROTECTED]
> > > >
> > > > Shortcut URL to this page:
> > > > http://groups.yahoo.com/group/php-list
> > > >
> > > >
> > > >
> > > > ---------------------------------
> > > > YAHOO! GROUPS LINKS
> > > >
> > > >
> > > > Visit your group "php-list" on the web.
> > > >
> > > > To unsubscribe from this group, send an email to:
> > > > [EMAIL PROTECTED]
> > > >
> > > > Your use of Yahoo! Groups is subject to the Yahoo!
> > > > Terms of Service.
> > > >
> > > >
> > > > ---------------------------------
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > __________________________________________________________
> > > > Enjoy this Diwali with Y! India Click here
> > > > http://in.promos.yahoo.com/fabmall/index.html
> > > >
> > > >
> > > > Community email addresses:
> > > > Post message: [email protected]
> > > > Subscribe: [EMAIL PROTECTED]
> > > > Unsubscribe: [EMAIL PROTECTED]
> > > > List owner: [EMAIL PROTECTED]
> > > >
> > > > Shortcut URL to this page:
> > > > http://groups.yahoo.com/group/php-list
> > > >
> > > >
> > > > ------------------------------
> > > > YAHOO! GROUPS LINKS
> > > >
> > > >
> > > > - Visit your group
> > "php-list<http://groups.yahoo.com/group/php-list>"
> > > > on the web.
> > > > - To unsubscribe from this group, send an email to:
> > > > [EMAIL PROTECTED]<
> > >
> >
>
[EMAIL PROTECTED]<http://[EMAIL PROTECTED]/?subject=Unsubscribe>
> > > >
> > > > - Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> > > > Service <http://docs.yahoo.com/info/terms/>.
> > > >
> > > >
> > > > ------------------------------
> > > >
> > >
> > >
> > >
> > > --
> > > Get a laptop for only $5
> > > http://www.ezlaptop.com/index.php?ref=43004
> > >
> > >
> > > [Non-text portions of this message have been removed]
> > >
> > >
> > >
> > > Community email addresses:
> > > Post message: [email protected]
> > > Subscribe: [EMAIL PROTECTED]
> > > Unsubscribe: [EMAIL PROTECTED]
> > > List owner: [EMAIL PROTECTED]
> > >
> > > Shortcut URL to this page:
> > > http://groups.yahoo.com/group/php-list
> > >
> > >
> > > ------------------------------
> > > YAHOO! GROUPS LINKS
> > >
> > >
> > > - Visit your group
> > "php-list<http://groups.yahoo.com/group/php-list>"
> > > on the web.
> > > - To unsubscribe from this group, send an email to:
> > >
> >
>
[EMAIL PROTECTED]<[EMAIL PROTECTED]>
> > > - Your use of Yahoo! Groups is subject to the Yahoo! Terms
> of
> > > Service <http://docs.yahoo.com/info/terms/>.
> > >
> > >
> > > ------------------------------
> > >
> >
> >
> > [Non-text portions of this message have been removed]
> >
> >
>
>
> Mark Weinstock
> [EMAIL PROTECTED]
> ***************************************
> You can't demand something as a "right" unless you are willing to
> fight to death to defend everyone else's right to the same thing.
> ***************************************
>
>
>
> __________________________________
> Yahoo! FareChase: Search multiple travel sites in one click.
> http://farechase.yahoo.com
>
>
> Community email addresses:
> Post message: [email protected]
> Subscribe: [EMAIL PROTECTED]
> Unsubscribe: [EMAIL PROTECTED]
> List owner: [EMAIL PROTECTED]
>
> Shortcut URL to this page:
> http://groups.yahoo.com/group/php-list
>
>
>
> ---------------------------------
> YAHOO! GROUPS LINKS
>
>
> Visit your group "php-list" on the web.
>
> To unsubscribe from this group, send an email to:
> [EMAIL PROTECTED]
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service.
>
>
> ---------------------------------
>
>
>
>
> ---------------------------------
> Yahoo! FareChase - Search multiple travel sites in one click.
>
> [Non-text portions of this message have been removed]
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
------------------------ Yahoo! Groups Sponsor --------------------~-->
Most low income households are not online. Help bridge the digital divide today!
http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/HKFolB/TM
--------------------------------------------------------------------~->
Community email addresses:
Post message: [email protected]
Subscribe: [EMAIL PROTECTED]
Unsubscribe: [EMAIL PROTECTED]
List owner: [EMAIL PROTECTED]
Shortcut URL to this page:
http://groups.yahoo.com/group/php-list
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php-list/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/