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

Posted by Jerry Stuckle on 10/17/06 20:45

Johnny wrote:
> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
> news:OIadnSwb9dbnL6nYnZ2dnUVZ_oidnZ2d@comcast.com...
>
>>Johnny wrote:
>>
>>>"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
>>>
>>>
>>
>>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
==================

 

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

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