Connecting Tech Pros Worldwide Help | Site Map

How to return a file

Bryan
Guest
 
Posts: n/a
#1: Oct 17 '06
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?

clashers5@gmail.com
Guest
 
Posts: n/a
#2: Oct 17 '06

re: How to return a file


Yes.
Put the foo.js text in the bar.php file or read it from a database or
text file and have php spit it out. Whatever suits your fancy.

Then, when bar.php receives the query string variable file with the
value foo, have it first print the type of the output with this code:

header('Content-type: text/javascript');

and then have it print the contents of foo.js (whereever you may have
stored them)

HTH
-Joe

On Oct 16, 10:41 pm, "Bryan" <BTRichard...@gmail.comwrote:
Quote:
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?
Tyrone Slothrop
Guest
 
Posts: n/a
#3: Oct 17 '06

re: How to return a file


On 16 Oct 2006 19:41:14 -0700, "Bryan" <BTRichardson@gmail.comwrote:
Quote:
>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().
Bryan
Guest
 
Posts: n/a
#4: Oct 17 '06

re: How to return a file


Thanks for the help guys, but I can't get it to work.

As an example, Google does the following in GMail. How does this work?

<script src="?view=page&amp;name=browser&amp;ver=o9cia6293 i3x"></script>

Johnny
Guest
 
Posts: n/a
#5: Oct 17 '06

re: How to return a file



"Tyrone Slothrop" <ts@paranoids.comwrote in message
news:8hi8j2le321hqdkoouo2qnp9b8n11itnko@4ax.com...
Quote:
On 16 Oct 2006 19:41:14 -0700, "Bryan" <BTRichardson@gmail.comwrote:
>
Quote:
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


Jerry Stuckle
Guest
 
Posts: n/a
#6: Oct 17 '06

re: How to return a file


Bryan wrote:
Quote:
Thanks for the help guys, but I can't get it to work.
>
As an example, Google does the following in GMail. How does this work?
>
<script src="?view=page&amp;name=browser&amp;ver=o9cia6293 i3x"></script>
>
Google is using javascript to pass a url to the server. This is
something completely different - unrelated to include.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Jerry Stuckle
Guest
 
Posts: n/a
#7: Oct 17 '06

re: How to return a file


Johnny wrote:
Quote:
"Tyrone Slothrop" <ts@paranoids.comwrote in message
news:8hi8j2le321hqdkoouo2qnp9b8n11itnko@4ax.com...
>
Quote:
>>On 16 Oct 2006 19:41:14 -0700, "Bryan" <BTRichardson@gmail.comwrote:
>>
>>
Quote:
>>>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
>
>
What a confusing way to do it - when Joe's method works quite well.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Johnny
Guest
 
Posts: n/a
#8: Oct 17 '06

re: How to return a file



"Jerry Stuckle" <jstucklex@attglobal.netwrote in message
news:OIadnSwb9dbnL6nYnZ2dnUVZ_oidnZ2d@comcast.com. ..
Quote:
Johnny wrote:
Quote:
"Tyrone Slothrop" <ts@paranoids.comwrote in message
news:8hi8j2le321hqdkoouo2qnp9b8n11itnko@4ax.com...
Quote:
>On 16 Oct 2006 19:41:14 -0700, "Bryan" <BTRichardson@gmail.comwrote:
>
>
>>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
Quote:
Quote:
from a PHP file.
a PHP file can be called from a script in HTML in the same way as you
can
Quote:
Quote:
post to a PHP file from a form using action="myscript.php" you just
refer to
Quote:
Quote:
the file.

Also re clashers5: my understanding is that headers are not needed as
the
Quote:
Quote:
script is embedded as part of the http being sent to the browser with
header
Quote:
Quote:
started for that, it's being included just as foo.js would have been.
foo.js
Quote:
Quote:
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
Quote:
Quote:
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
>
What a confusing way to do it - when Joe's method works quite well.
>
what a confusing and totally uncalled for response: when argument fails just
dismiss... oi!

what is so confusing about replacing 'foo.js' with 'script.php?foo' after
all it is that simple, the rest is illustration padding...
and BTW in case you didn't notice Joe and I are essentailly in agreement
except for the header part, which you don't argue with, just dismiss the
entire post. Anyone can dismiss. All I have done is expand on what Joe said
with an example but showing that it works just fine without the header.
And your contribution is...even more confusing but lacking any substance.



Jerry Stuckle
Guest
 
Posts: n/a
#9: Oct 17 '06

re: How to return a file


Johnny wrote:
Quote:
"Jerry Stuckle" <jstucklex@attglobal.netwrote in message
news:OIadnSwb9dbnL6nYnZ2dnUVZ_oidnZ2d@comcast.com. ..
>
Quote:
>>Johnny wrote:
>>
Quote:
>>>"Tyrone Slothrop" <ts@paranoids.comwrote in message
>>>news:8hi8j2le321hqdkoouo2qnp9b8n11itnko@4ax.com ...
>>>
>>>
>>>>On 16 Oct 2006 19:41:14 -0700, "Bryan" <BTRichardson@gmail.comwrote:
>>>>
>>>>
>>>>
>>>>>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
>
Quote:
Quote:
>>>from a PHP file.
>>>a PHP file can be called from a script in HTML in the same way as you
>
can
>
Quote:
Quote:
>>>post to a PHP file from a form using action="myscript.php" you just
>
refer to
>
Quote:
Quote:
>>>the file.
>>>
>>>Also re clashers5: my understanding is that headers are not needed as
>
the
>
Quote:
Quote:
>>>script is embedded as part of the http being sent to the browser with
>
header
>
Quote:
Quote:
>>>started for that, it's being included just as foo.js would have been.
>
foo.js
>
Quote:
Quote:
>>>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
>
Quote:
Quote:
>>>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
>>>
>>>
>>
>>What a confusing way to do it - when Joe's method works quite well.
>>
>
what a confusing and totally uncalled for response: when argument fails just
dismiss... oi!
>
what is so confusing about replacing 'foo.js' with 'script.php?foo' after
all it is that simple, the rest is illustration padding...
and BTW in case you didn't notice Joe and I are essentailly in agreement
except for the header part, which you don't argue with, just dismiss the
entire post. Anyone can dismiss. All I have done is expand on what Joe said
with an example but showing that it works just fine without the header.
And your contribution is...even more confusing but lacking any substance.
>
>
>
No, I disagree.

Yes, your answer and Joe's do the same thing. But his is
straightforward and easy to understand. Yours is more complicated,
harder to understand and more prone to errors - especially when you have
to later modify it.

KISS. And Joe's is much simpler.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Rik
Guest
 
Posts: n/a
#10: Oct 18 '06

re: How to return a file


Jerry Stuckle wrote:
Quote:
KISS. And Joe's is much simpler.

Script building rule #1: the most simple solution is often the right one.

:-)
--
Rik Wasmus


Johnny
Guest
 
Posts: n/a
#11: Oct 18 '06

re: How to return a file



"Jerry Stuckle" <jstucklex@attglobal.netwrote in message
news:7rydnS6W7rJT3ajYnZ2dnUVZ_vydnZ2d@comcast.com. ..
<snip/>
Quote:
Quote:
Quote:
>What a confusing way to do it - when Joe's method works quite well.
>
what a confusing and totally uncalled for response: when argument fails
just
Quote:
Quote:
dismiss... oi!

what is so confusing about replacing 'foo.js' with 'script.php?foo'
after
Quote:
Quote:
all it is that simple, the rest is illustration padding...
and BTW in case you didn't notice Joe and I are essentailly in agreement
except for the header part, which you don't argue with, just dismiss the
entire post. Anyone can dismiss. All I have done is expand on what Joe
said
Quote:
Quote:
with an example but showing that it works just fine without the header.
And your contribution is...even more confusing but lacking any
substance.
Quote:
Quote:

>
No, I disagree.
>
Yes, your answer and Joe's do the same thing.
OK...
Quote:
But his is
straightforward and easy to understand.
That's clearly _not_ the case as Bryan responded "Thanks for the help guys,
but I can't get it to work."
Quote:
Yours is more complicated,
harder to understand and more prone to errors - especially when you have
to later modify it.
err...since Joe's didn't cut it , I felt that expansion might help.
and I'm very surprised that you find such a simple example as the few lines
I supplied hard to understand.
LOL The "prone to errors" assertion is interesting in such a short piece of
script...

It was meant as the simplest, yet complete, _working_ example of returning
javascipt using a PHP script.
A place to start from...
the basic minimum HTML tags around the script tag,
<html>...<script...></script><html>
don't see what's so prone to error there... I must be missing something

the other the bare minimum to return some javascript:
<?php #foo.php
$js = do_what_you_do_to_get_the_javascript();
echo $js;
?>
prone to error? well I guess do_what_you_do_to_get_the_javascript(); is
prone to error but it is just as prone when done from Joe's same difference.
Quote:
>
KISS. And Joe's is much simpler.
>
The point of the exercise is to help Bryan "get it to work"
Clearly, although simpler, Joe's post failed in that end.
Has my post failed to help Bryan get it to work? Only Bryan can say.

Just in case Bryan hasn't got it to work yet:
I'll simplify bits for Jerry and expand some more for Bryan, best of both
worlds :-)

in the html (simplified...just the script line from the file):
<script type='text/javascript' src='bar.php?file=foo'></script>

in the javascript file foo.js:
alert("hi there!");

in the PHP file, with Joe's header:
<?php #bar.php
header('Content-type: text/javascript');
echo file_get_contents($_GET['file'].".js");
?>

or even simpler, which Jerry professes to like :-), without Joe's header
<?php #bar.php
echo file_get_contents($_GET['file'].".js");
?>

This works with and without the header in bar.php
minimum 1 code line in each file. simple enough? and yet not so simple as
Joe's post but yet expanded to a working example.

Hope this helps get it to work for you Bryan.



Johnny
Guest
 
Posts: n/a
#12: Oct 18 '06

re: How to return a file



"Rik" <luiheidsgoeroe@hotmail.comwrote in message
news:d0a0$45356b2a$8259c69c$20598@news2.tudelft.nl ...
Quote:
Jerry Stuckle wrote:
Quote:
KISS. And Joe's is much simpler.
>
>
Script building rule #1: the most simple solution is often the right one.
>
:-)
--
Rik Wasmus
>
'cept in this case there was no script in the "most simple solution" as
defined by Jerry and which of course for the OP wasn't a solution, so no and
no. :-)


Jerry Stuckle
Guest
 
Posts: n/a
#13: Oct 18 '06

re: How to return a file


Johnny wrote:
Quote:
"Rik" <luiheidsgoeroe@hotmail.comwrote in message
news:d0a0$45356b2a$8259c69c$20598@news2.tudelft.nl ...
>
Quote:
>>Jerry Stuckle wrote:
>>
Quote:
>>>KISS. And Joe's is much simpler.
>>
>>
>>Script building rule #1: the most simple solution is often the right one.
>>
>>:-)
>>--
>>Rik Wasmus
>>
>
'cept in this case there was no script in the "most simple solution" as
defined by Jerry and which of course for the OP wasn't a solution, so no and
no. :-)
>
>
No, he didn't type it out. Rather than give an answer, Joe did
something better - he have guidance on how to do it. That way the
operator has a chance to learn something.

It's exactly what I do when teaching classes. And if they continue to
have problems, I give them more detailed guidance.

But just giving them an answer on something like this doesn't give him a
chance to learn.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Rik
Guest
 
Posts: n/a
#14: Oct 18 '06

re: How to return a file


Jerry Stuckle wrote:
Quote:
Johnny wrote:
Quote:
>"Rik" <luiheidsgoeroe@hotmail.comwrote in message
>news:d0a0$45356b2a$8259c69c$20598@news2.tudelft.n l...
>>
Quote:
>>Jerry Stuckle wrote:
>>>
>>>KISS. And Joe's is much simpler.
>>>
>>>
>>Script building rule #1: the most simple solution is often the
>>right one.
>>>
>>
>'cept in this case there was no script in the "most simple solution"
>as defined by Jerry and which of course for the OP wasn't a
>solution, so no and no. :-)
>>
>>
>
No, he didn't type it out. Rather than give an answer, Joe did
something better - he have guidance on how to do it. That way the
operator has a chance to learn something.
>
It's exactly what I do when teaching classes. And if they continue to
have problems, I give them more detailed guidance.
>
But just giving them an answer on something like this doesn't give
him a chance to learn.
It is indeeed what people should do. Even after all this time (and my
little hiatus) I haven't learned that yet.

The problem is that it's often simpler and faster to type out a solution
then explain it, and I'm lazy offcourse :-)

(Oh: and I haven't repaired my sig-seperator for nothing, my sig does not
have to be quoted...)

--
Grtz,

Rik Wasmus


Jerry Stuckle
Guest
 
Posts: n/a
#15: Oct 18 '06

re: How to return a file


Rik wrote:
Quote:
Jerry Stuckle wrote:
>
Quote:
>>Johnny wrote:
>>
Quote:
>>>"Rik" <luiheidsgoeroe@hotmail.comwrote in message
>>>news:d0a0$45356b2a$8259c69c$20598@news2.tudelft .nl...
>>>
>>>
>>>>Jerry Stuckle wrote:
>>>>
>>>>
>>>>>KISS. And Joe's is much simpler.
>>>>
>>>>
>>>>Script building rule #1: the most simple solution is often the
>>>>right one.
>>>>
>>>
>>>'cept in this case there was no script in the "most simple solution"
>>>as defined by Jerry and which of course for the OP wasn't a
>>>solution, so no and no. :-)
>>>
>>>
>>
>>No, he didn't type it out. Rather than give an answer, Joe did
>>something better - he have guidance on how to do it. That way the
>>operator has a chance to learn something.
>>
>>It's exactly what I do when teaching classes. And if they continue to
>>have problems, I give them more detailed guidance.
>>
>>But just giving them an answer on something like this doesn't give
>>him a chance to learn.
>
>
It is indeeed what people should do. Even after all this time (and my
little hiatus) I haven't learned that yet.
>
The problem is that it's often simpler and faster to type out a solution
then explain it, and I'm lazy offcourse :-)
>
(Oh: and I haven't repaired my sig-seperator for nothing, my sig does not
have to be quoted...)
>
Actually, I think you do a pretty good job at it, Rik.

I should also add - when it comes to more complicated problems, often I
will supply an answer, also. Mainly because there's a point where an
example is necessary to explain what you mean.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Bryan
Guest
 
Posts: n/a
#16: Oct 23 '06

re: How to return a file


Sorry I'm just now getting around to looking at this some more. It's
been a long week! I'll try this again and let you guys know if it
works.

Thanks again for all the help you guys have offered! Again, I'll let
you know if I get it to work for me.

Bryan

Johnny wrote:
Quote:
"Jerry Stuckle" <jstucklex@attglobal.netwrote in message
news:7rydnS6W7rJT3ajYnZ2dnUVZ_vydnZ2d@comcast.com. ..
<snip/>
Quote:
Quote:
>>What a confusing way to do it - when Joe's method works quite well.
>>
>
what a confusing and totally uncalled for response: when argument fails
just
Quote:
Quote:
dismiss... oi!
>
what is so confusing about replacing 'foo.js' with 'script.php?foo'
after
Quote:
Quote:
all it is that simple, the rest is illustration padding...
and BTW in case you didn't notice Joe and I are essentailly in agreement
except for the header part, which you don't argue with, just dismiss the
entire post. Anyone can dismiss. All I have done is expand on what Joe
said
Quote:
Quote:
with an example but showing that it works just fine without the header.
And your contribution is...even more confusing but lacking any
substance.
Quote:
Quote:
>
>
>
No, I disagree.

Yes, your answer and Joe's do the same thing.
OK...
>
Quote:
But his is
straightforward and easy to understand.
>
That's clearly _not_ the case as Bryan responded "Thanks for the help guys,
but I can't get it to work."
>
Quote:
Yours is more complicated,
harder to understand and more prone to errors - especially when you have
to later modify it.
>
err...since Joe's didn't cut it , I felt that expansion might help.
and I'm very surprised that you find such a simple example as the few lines
I supplied hard to understand.
LOL The "prone to errors" assertion is interesting in such a short piece of
script...
>
It was meant as the simplest, yet complete, _working_ example of returning
javascipt using a PHP script.
A place to start from...
the basic minimum HTML tags around the script tag,
<html>...<script...></script><html>
don't see what's so prone to error there... I must be missing something
>
the other the bare minimum to return some javascript:
<?php #foo.php
$js = do_what_you_do_to_get_the_javascript();
echo $js;
?>
prone to error? well I guess do_what_you_do_to_get_the_javascript(); is
prone to error but it is just as prone when done from Joe's same difference.
>
Quote:

KISS. And Joe's is much simpler.
The point of the exercise is to help Bryan "get it to work"
Clearly, although simpler, Joe's post failed in that end.
Has my post failed to help Bryan get it to work? Only Bryan can say.
>
Just in case Bryan hasn't got it to work yet:
I'll simplify bits for Jerry and expand some more for Bryan, best of both
worlds :-)
>
in the html (simplified...just the script line from the file):
<script type='text/javascript' src='bar.php?file=foo'></script>
>
in the javascript file foo.js:
alert("hi there!");
>
in the PHP file, with Joe's header:
<?php #bar.php
header('Content-type: text/javascript');
echo file_get_contents($_GET['file'].".js");
?>
>
or even simpler, which Jerry professes to like :-), without Joe's header
<?php #bar.php
echo file_get_contents($_GET['file'].".js");
?>
>
This works with and without the header in bar.php
minimum 1 code line in each file. simple enough? and yet not so simple as
Joe's post but yet expanded to a working example.
>
Hope this helps get it to work for you Bryan.
Closed Thread