473,770 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to return a file

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=f oo" and have bar.php echo foo.js back to the script
element. Is this possible?

Oct 17 '06 #1
15 1640
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...@g mail.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=f oo" and have bar.php echo foo.js back to the script
element. Is this possible?
Oct 17 '06 #2
On 16 Oct 2006 19:41:14 -0700, "Bryan" <BT**********@g mail.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.ph p?file=foo'); }

However, you can create a function:

function foo($file)
{
include ('$file.js');
}

<?=foo('foo') ?>

Also review file_get_conten ts() and readfile().
Oct 17 '06 #3
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=brows er&amp;ver=o9ci a6293i3x"></script>

Oct 17 '06 #4

"Tyrone Slothrop" <ts@paranoids.c omwrote in message
news:8h******** *************** *********@4ax.c om...
On 16 Oct 2006 19:41:14 -0700, "Bryan" <BT**********@g mail.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=f oo" 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.ph p?file=foo'); }

However, you can create a function:

function foo($file)
{
include ('$file.js');
}

<?=foo('foo') ?>

Also review file_get_conten ts() 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="myscrip t.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
Oct 17 '06 #5
Bryan wrote:
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=brows er&amp;ver=o9ci a6293i3x"></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.
js*******@attgl obal.net
=============== ===
Oct 17 '06 #6
Johnny wrote:
"Tyrone Slothrop" <ts@paranoids.c omwrote in message
news:8h******** *************** *********@4ax.c om...
>>On 16 Oct 2006 19:41:14 -0700, "Bryan" <BT**********@g mail.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?fil e=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.ph p?file=foo'); }

However, you can create a function:

function foo($file)
{
include ('$file.js');
}

<?=foo('foo') ?>

Also review file_get_conten ts() 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="myscrip t.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.
js*******@attgl obal.net
=============== ===
Oct 17 '06 #7

"Jerry Stuckle" <js*******@attg lobal.netwrote in message
news:OI******** *************** *******@comcast .com...
Johnny wrote:
"Tyrone Slothrop" <ts@paranoids.c omwrote in message
news:8h******** *************** *********@4ax.c om...
>On 16 Oct 2006 19:41:14 -0700, "Bryan" <BT**********@g mail.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.ph p?file=foo'); }

However, you can create a function:

function foo($file)
{
include ('$file.js');
}

<?=foo('foo')? >

Also review file_get_conten ts() 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="myscrip t.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.

Oct 17 '06 #8
Johnny wrote:
"Jerry Stuckle" <js*******@attg lobal.netwrote in message
news:OI******** *************** *******@comcast .com...
>>Johnny wrote:
>>>"Tyrone Slothrop" <ts@paranoids.c omwrote in message
news:8h***** *************** ************@4a x.com...
On 16 Oct 2006 19:41:14 -0700, "Bryan" <BT**********@g mail.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?f ile=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.ph p?file=foo'); }

However, you can create a function:

function foo($file)
{
include ('$file.js');
}

<?=foo('foo ')?>

Also review file_get_conten ts() 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="myscrip t.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.
js*******@attgl obal.net
=============== ===
Oct 17 '06 #9
Rik
Jerry Stuckle wrote:
KISS. And Joe's is much simpler.

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

:-)
--
Rik Wasmus
Oct 17 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3993
by: Paul | last post by:
Hi, Does anyone know how I would be able to drag a single file onto my applications icon and have it run some predefined code. What I want is to drop an .mp3 file onto my applications icon (not the apps form) and perform the necessary actions then give a confirmation when these actions are done then quit.
13
3796
by: J. Campbell | last post by:
I'm wanting to output a text header file in front of the data portion of an output file. However when I use "\n" or "endl" as end of line, it just puts a 0x0a in the file(which is non-printing)...in Windows you need the (0x0d 0x0a) pair, if you want a new-line in a text editor. What's the correct way to get this 2-byte sequence into a file? Thanks #include <iostream>
12
2332
by: Mike Brashars | last post by:
Hi all, I have been searching for a week and am unable to find and example to "Populate picklist from directory and return file name". I have a php script that reads a log file and plots a graph. Right now, the log name is hard coded. The logs are archived each day in the form of say ddmmyy.log and I would like to put a drop down list in the script that would allow my script to run off the "log" picked or default to the current "hard...
6
10255
by: Clint Stowers | last post by:
Using Acc2k Can anyone suggest some sample code for returning the date of a Linked File? I am linking MyFile.xls as tblMyFile. Simply put, somewhere on a form I would like to the date of the xls file. Any suggestion appreciated. Thanks in advance
9
10614
by: AP | last post by:
Is there anyway to determine what the modified or create date is for a file? In my example I am uploading a text file using the following to select the filename: GetOpenFileName Lib "COMDLG32.DLL". Is there anyway to point to that file and return the information about the file properties? Size, date modified, created, etc? Thanks
4
2296
by: tasahmed | last post by:
Hello Friends, I wrote a function which scans the current working directory and lists out details such as directory/file owner, permission etc. The output of this script can be viewing in the monitor when I give the command print_r which is printed out in a array format. The problem I facing is I want this output in a text file, but I have tried so many things it is not working I am copying my code below, I need help in this urgently....
75
3559
by: ume$h | last post by:
/* I wrote the following program to calculate no. of 'a' in the file c:/1.txt but it fails to give appropriate result. What is wrong with it? */ #include"stdio.h" int main(void) { FILE *f; char ch; long int a=0;
1
5607
by: shyaminf | last post by:
hi everybody! iam facing a problem with the transfer of file using servlet programming. i have a code for uploading a file. but i'm unable to execute it using tomcat5.5 server. kindly help me how to execute it using tomcat server5.5. the code is as follows. if you have any other coding regarding this, please send me.it's urgent. import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*;
1
1818
by: yanni127 | last post by:
hi everyone I've got a file : fstream in ("f.in"); after searching, file pointer is at the end of file and I wanna return it to the begginnig for other tasks. what statement can I use?
3
5881
by: paleman | last post by:
Hi. I'm trying to write my own version of opendir function on Windows XP.Within that function I'm calling open function: fd = open(path, O_RDONLY, 0); and this fails when path points to a directory. Does anyone know how to open a directory on Win OS so it returns a file descriptor to it.Maybe open should be given another parameters or some other function exists that I don't know of.
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9453
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8929
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7451
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.