Via AJAX/ or a Javascript framework like Jquery of course. However my question isn’t about the .js but rather the <?php> .
I wanted to make a server call via AJAX to php and have it make a video take with the correct attributes and stuff and shove it into a div that was already pre made. However when I ran it nothing happened. I checked to see if they were any syntax errors but as far as I can tell there aren’t any. So I’m going to post the code here and see of anyone can figure out if I did something wrong before I find it the error myself. Any help would be most appreciated.
[CODE]<?php
$n;
$dom = new DOMDocument();
$id = $dom->getElementById(‘videos’);
/* Loop through the directory and get vidoes*/
function videosLoad(){
$n = sizeof(readdir(‘/videos’));
if ($handle == opendir(‘/videos’)) {
/* This is the correct way to loop over the directory. */
while (false !== ($entry = readdir($handle))) {
/*Video tag*/
$video = $dom->createElement(‘video’);
$video->createAttribute(‘id’)->value = ‘example_video_’.$n;
$video->createAttribute(‘class’)->value = ‘video-js vjs-default-skin’;
$video->createAttribute(‘controls preload’)->value = ‘auto’;
$video->createAttribute(‘width’)->value=’640′;
$video->createAttribute(‘height’)->value=’264′;
$video->createAttribute(‘data-setup’)->value = “{ ‘controls’: true, ‘autoplay’:false, ‘prelaod’: ‘auto’}”;
/*source tags*/
$source = $dom->createElement(‘source’);
$source->createAttribute(‘src’)->value= $entry;
$source->createAttribute(‘type’)->value= ‘video/mp4’;
/*script tags:: May not need it
$script = $dom->createElement(‘script’);
$script->createAtrribute(‘type’);
$script->value = “text/javascript”;
$script->appendChild(“var vObj =
document.getElementById(“example_video_”‘.$n’);
document.getElementById(“vidoes”).appenedChild(vObj);”);
*/
$video->appendChild($source);
$id->appendChild($video);
/*
‘<video id=”example_video_” class=”video-js vjs-default-skin”
controls preload=”auto” width=”640″ height=”264″
data-setup='{“example_option”:true}’>
<source src=”‘$entry'” type=’video/mp4’/>
</video>’;
“<script type=”text/javascript”>
var vObj = document.getElementById(“example_video_”‘.$n’);
document.getElementById(“vidoes”).appenedChild(vObj);
</script>”
*/
$n–;
}
/* This is the WRONG way to loop over the directory.
while ($entry = readdir($handle)) {
echo “$entryn”;
}
*/
closedir($handle);
}
}
/*Use Video.js as a the containter for the video*/
?>