You are here: Re: How to return a file « PHP Programming Language « IT news, forums, messages
Re: How to return a file

Posted by Johnny on 10/17/06 07:05

"Tyrone Slothrop" <ts@paranoids.com> wrote in message
news:8hi8j2le321hqdkoouo2qnp9b8n11itnko@4ax.com...
> On 16 Oct 2006 19:41:14 -0700, "Bryan" <BTRichardson@gmail.com> wrote:
>
> >Hello all,
> >
> >In some html code I have the following:
> >
> ><script type='text/javascript' src='foo.js'></script>
> >
> >However, I'd like to replace 'foo.js' with something like
> >"bar.php?file=foo" and have bar.php echo foo.js back to the script
> >element. Is this possible?
>
> First, a query string will not work with an include, like:
> <? include('bar.php?file=foo'); }
>
> However, you can create a function:
>
> function foo($file)
> {
> include ('$file.js');
> }
>
> <?=foo('foo')?>
>
> Also review file_get_contents() and readfile().

imho that makes things way more complicated than they are...
the OP is refering to calling a PHP file from a script in an HTML file not
from a PHP file.
a PHP file can be called from a script in HTML in the same way as you can
post to a PHP file from a form using action="myscript.php" you just refer to
the file.

Also re clashers5: my understanding is that headers are not needed as the
script is embedded as part of the http being sent to the browser with header
started for that, it's being included just as foo.js would have been. foo.js
would not have had a header included in the file.

so you do something like these files (text as between and not
inlcuding the dashed lines):
-----------
<!-- file this.html -->
<html>
<head>
<title></title>
</head>
<body>
<script type='text/javascript' src='js3.php'></script>
</body>
</html>
------------


and in file js3.php:
-----------
<?php
# this is file js3.php with some js to send back to the browser
# get the js from a db, file or wherever you like
$js = "alert(\"hi there!\");";

echo $js;
?>
----------

So all you have to do is either echo or print the js to get it into the
browser as it is embedded as part of the normal HTTP being transmitted to
the
browser within the existing html header.


Here's what w3 has to say about scripts:
http://www.w3.org/TR/html401/interact/scripts.html

 

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

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