Forum Moderators: coopster
I have an HTML form that uses JavaScript to go to different video clips that I have already embeded in specific web pages (i.e. video1.html, video2.html, video3.html, etc.) Now, I think that if my form uses the "POST" method I should be able to dynamically have a page called "video.php" to play all videos instead of having to manually create these page.
These videos are files like "video1.wmv" or playlists such as "video.m3u".
Can you please help me with the "video.php" and what else do I need on the following form?
<html><head><title>Video Selection</title>
<script language="JavaScript">
<!--
//
function openDir(form) {
window.location=(form.dir.options[form.dir.selectedIndex].value);
}
// -->
</script>
</head>
<body>
<form name="Video_On_Demand">
<div align="center"><p align="left"><select name="dir" size="1">
<option>Select a Video</option>
<option value="video1.html>Week 1
<option value="video2.html">Week 2
<option value="video3.html">Week 3
<option value="video4.html">Week 4
</select><input type="button" name="button" value="Go!" onclick="openDir(this.form);"> </p>
</div>
</form>
</body>
</html>
<option value="video1.html>Week 1 <option value="video2.html">Week 2 <option value="video3.html">Week 3 <option value="video4.html">Week 4 could easily be changed to:
<option value="video.php?vid=video1&type=wmv>Week 1 <option value="video.php?vid=video2&type=mov">Week 2 <option value="video.php?vid=video3&type=wmv">Week 3 <option value="video.php?vid=video1$type=m3u">Week 4 and video.php could be something like:
<?php
$thisVideo = $_POST['vid'].".".$_POST['type'];
switch $_POST['type'] {
case "wmv":
$thisClass="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95";
$thisType="application/x-oleobject";
$thisCodebase="http://activex.microsoft.com/..et..al..";
$thisEmbedType="application/x-mplayer2";
$thisCustom="<param name='autostart' value='true'><param name='autorewind' value='true'>";
$thisEmbedCustom="autostart=true showpositioncomtrols=1";
break;
case "mov":
$thisClass="clsid:for_quicktime_movies";
$thisType="video/quicktime";
$thisCodebase="http://quicktime_code_base_uri/..et..al..";
$thisEmbedType="video/quicktime";
$thisCustom="";
$thisEmbedCustom="";
break;
[dupe above for other media types]
}
echo "<object id='thamovie' classid='".$thisClass."' type='".$thisType."' codebase='".$thisCodebase;
echo "' width=320 height=240>\n";
echo "<param name='filename' value='".$thisVideo."'>\n";
echo $thisCustom;
echo "<embed type='".$thisEmbedType."' name='thamovie' src='".$thisVideo;
echo " width=320 height=240 ".$thisEmbedCustom."></embed>\n";
echo "</object>\n";
?>
You could include other things, too like alternate widths and heights, etc.
See the PHP manual [php.net] for more info about the "switch" statement.
<edit>broke lines unnaturally to avoid confusing wrap</edit>
PHP Parse error: parse error, expecting `'('' in D:\Inetpub\wwwroot\bulungu\videos\video.php on line 4
Of course, bulungu is the login/account name. It seems like something is expected on line 4 of video.php.
Any idea?
Regards
I tried switch ($_POST['type']) { on what I thought was line 4 but I still got the same parse error. I went back and deleted the break so that the "switch" statement starts on line 3 to see if that's where the error was coming from. I received the same message saying that the parse error was on line 4.
I now think that it has something to do with the first "case" statement since PHP executes statement by statement instead of line by line. I checked the PHP manual, and to me it seems like the string is properly double-quoted ("") and does have the colon (:) at the end. Single-quoting the string 'wmv' did not help either.
Any idea?
Thanks in advance.
bulungu
case "wmv": should be case "wmv"; (; vs :)
But php won't play the videos for some reasons. Here is the new fatal error:
PHP Fatal error: Unable to open D:\Inetpub\wwwroot\bulungu\videos\video.php in Unknown on line 0
Oh boy, I've never heard of line 0 before. Maybe someone has. Help will be appreciated.
Actually, my idea was that you should add () to the switch statement you already have on the line that it is already on... Line 2.
<?php
$thisVideo = $_POST['vid'].".".$_POST['type'];
switch ($_POST['type']) {
Sometimes, when php encounters an error, it keeps reading past where the error is, becuase it tries to find what it is looking for, and then finally can't. So, it is possible to have an error on lines that are directly above where the error is recorded, but no error on the actual line that is in the 'error' message.
Also, I believe the "proper" and "safe" way to use the variable $_POST['type'] is to 'catch' the variable prior to using it is. EG:
$thisVideo = $_POST['vid'].".".$_POST['type'];
new line 2: $type = $_POST['type']; (added)
new line 3: switch ($type) {
This way the actual 'POST' variable could be tested for 'bad-stuff' before use. (testing not shown in the example) I don't think it's overly necessary here, but still a good habit.
Sorry, if this or the original post is confusing.
Hope it helps.
Justin
PS like I said before, switch/case are not something I use much, so not to technical with them... I'll leave it to the pro's now.
1: <?php 2: $thisVideo = $_POST['vid'].".".$_POST['type']; 3: 4: switch $_POST['type'] { Indeed, I mis-wrote originally. Should be:
switch ($_POST['type']) { Otherwise it goes as above:
case [i]condition1[/i]: [i]action to take[/i]; [i]more actions ...[/i]; break; case [i]condition2[/i]: [i]action to take[/i]; break; Check out the PHP manual page I linked to in my first message for "switch()" function info.
I added the () and the parse error is gone. The PhP page loads when I select a video and click "GO." However, the page is blank. It looks like it doesn't see the videos.
For testing purpose I have the videos and the html and the php files in the same folder. The address bar shows the URL like:
[example.com...] but the page is blank. The video "car1.wmv" can play when embedded in HTML but not in PHP. Do I need to specify a placeholder or something?
Please paste the resulting HTML (not the PHP, the view->source in the browser) that makes up the blank page you get, and we'll take a look. The solution will be related to how the HTML was written.
<object id='thamovie' classid='' type='' codebase='' width=320 height=240>
<param name='filename' value='.'>
<embed type='' name='thamovie' src='. width=320 height=240 ></embed>
</object>