View Full Version : HELP needed with php codes
In the following php code to embed wmv file in a webpage, is it possible to list more than one wmv file (so that I do not have to create one php file for each very one wmv file)? Would appreciate if someone could help. Thank you.
<?php
$file = $_REQUEST["file"];
if ($file == "something") {
$open = 'trial.wmv';
}
else {
$open = ' ';
}
Header("Content-type: video/x-ms-wmv");
echo $open;
?>
boxxertrumps
12-15-2006, 03:34 PM
<?php
$file = $_REQUEST["file"];
//info about music files is stored
$farray (
one=>a.wmv,
two=>b.wmv,
three=>c.wmv
)
// file not (!=) null ("")
if ($file != "") {
$open = $farray[$file];
}
else {
$open = ' ';
}
Header("Content-type: video/x-ms-wmv");
echo $open;
?>
the url would be request.php?file=(aray key name, one/two/three ect.)
Thanks for your input but there is an error here:
Parse error: parse error, unexpected T_DOUBLE_ARROW on line 5
thetestingsite
12-16-2006, 06:16 AM
$farray (
one=>a.wmv,
two=>b.wmv,
three=>c.wmv
)
Anything in the array must have quotes around it, or it will cause errors. Also, at the end of the array, you must have a semicolon. All of the corrections to the above quoted code are posted below in red.
$farray (
'one' => 'a.wmv',
'two' => 'b.wmv',
'three' => 'c.wmv'
);
Hope this helps.
Thanks for your input but the same error message still appear:
Parse error: parse error, unexpected T_DOUBLE_ARROW on line 5
thetestingsite
12-16-2006, 06:46 AM
Did you copy and paste the code that boxxertrumps posted, or did you just add that to a code that you already had? If you copied and pasted, line 5 is the first line of the array. Otherwise, we would need to see the code in order to find a solution.
I copied and pasted boxxertrumps' code and replaced the one which you corrected:
<?php
$file = $_REQUEST["file"];
//info about music files is stored
$farray (
'one' => 'a.wmv',
'two' => 'b.wmv',
'three' => 'c.wmv'
);
// file not (!=) null ("")
if ($file != "") {
$open = $farray[$file];
}
else {
$open = ' ';
}
Header("Content-type: video/x-ms-wmv");
echo $open;
?>
djr33
12-16-2006, 12:05 PM
Hmm... looks ok to me, not sure, though.
But.... umm... echo $open means echo 'a.wmv', not actually output the file...
There are several other functions in php that can do this.
For example--
echo file_get_contents($open);
However, I think there may be a more preferable function, but not sure.
Also, $file = $_REQUEST["file"]; is overkill. That leaves it open to cookies, post and get data, when you only need get (URL, like ...?var=value). (cookies are stored text files to set preferences for a user, etc., and post data is from a form (get can be too, but it is then sent as part of the url, not hidden, like post).
$file = $_GET["file"]; would do just fine.
REQUEST isn't really hurting, but I don't see any reason it would help.
Thank you very much for your input, I greatly appreciate it.
thetestingsite
12-16-2006, 04:49 PM
Ok, so I found the reason for your error message that appears with the script. The original is below and the correction is below that in red.
<?php
$file = $_REQUEST["file"];
//info about music files is stored
$farray (
'one' => 'a.wmv',
'two' => 'b.wmv',
'three' => 'c.wmv'
);
// file not (!=) null ("")
if ($file != "") {
$open = $farray[$file];
}
else {
$open = ' ';
}
Header("Content-type: video/x-ms-wmv");
echo $open;
?>
Correction:
<?php
$file = $_REQUEST["file"];
//info about music files is stored
$farray = array(
'one' => 'a.wmv',
'two' => 'b.wmv',
'three' => 'c.wmv'
);
// file not (!=) null ("")
if ($file != "") {
$open = $farray[$file];
}
else {
$open = ' ';
}
Header("Content-type: video/x-ms-wmv");
echo $open;
?>
I completely overlooked that the code had an array, but the array was never started. Hope this helps.
djr33, it could be a feature of the format that it allows a playlist to be passed instead of actual video data, like RAM does.
boxxertrumps
12-16-2006, 09:01 PM
sorry about the shoddy array...
this is the product of my tiny attention span...
Many thanks to both thetestingsite and boxxertrumps for your kind input.
I have just noticed that IE7 prompts one to save the media file when the URL is entered on the address bar :
http://domain.com/request.php?file=one
Is there a way to prevent this?
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.