<?php
error_reporting(0);
//$SITE_URL="http://shreebalajiinfotech.com/Android/Download_videos/";
$SITE_URL="http://localhost/";
$DIR="Videos";
if($_REQUEST['category']=="")
{
echo 'Please pass folder name';
}
$dir = $_REQUEST['category'];
$result = array();
$SUB=$DIR ."/" .$dir;
//var_dump(is_dir($DIR ."/" .$dir));
//$image="http://shreebalajiinfotech.com/Android/Download_videos/Videos/test1/119064635524.jpg";
$cdir = scandir($SUB);
//$files2 = scandir($dir, 1);
//print_r($cdir);
?>
<div id="video_container">
<?php
foreach ($cdir as $value)
//for ($i=0; $i<count($cdir); $i++)
{
// if ($cdir[$i] != '.' && $cdir[$i] != '..')
//{
//{
if (!in_array($value,array(".","..")))
{
/*echo "<pre>";
var_dump(each($value));
echo "</pre>";
echo $value;
*/
//echo $key[$value];
//print_r($cdir[$i]);
$values=explode('.',$value);
if($values[1]=="mp4")
{
//$result[]=$value;
//echo $cdir[$i];
//echo "<br/>";
?>
<script src="jquery.min.js"></script>
<script type='text/javascript'>
window.onload = function(){
// $(document).ready(function(e) {
//$('#submit<?=$value;?>').click({
var video = document.getElementById('my_video_<?=$value;?>');
var thecanvas = document.getElementById('thecanvas');
var img = document.getElementById('thumbnail_img');
var div = document.getElementById('Imagecontainer');
var sources = document.getElementById('video<?=$value;?>');
alert(sources.src);
var videoname=sources.src.substring(sources.src.lastIndexOf('/')+1);
setTimeout(video.pause(draw(video, thecanvas, img,videoname)),6000);
if(video.paused==true)
{
setTimeout(video.play(),2000);
}
function draw(video, thecanvas, img,videoname)
{
alert(video);
// get the canvas context for drawing
var context = thecanvas.getContext('2d');
// draw the video contents into the canvas x, y, width, height
context.drawImage(video, 0, 0, thecanvas.width, thecanvas.height);
// get the image data from the canvas object
var dataURL = thecanvas.toDataURL();
alert(dataURL);
// set the source of the img tag
var img1 = document.createElement('img');
img1.setAttribute('src', dataURL);
document.getElementById('Imagecontainer').appendChild(img1);
img1.setAttribute('src', dataURL);
$.ajax({
type: "POST",
url: "upload.php",
data: {image: dataURL,folder:'<?=$_REQUEST['category'];?>',videoname:videoname},
success: function(response) {
alert(response);
}
});
}
};
</script>
<video id="my_video_<?=$value;?>" class="<?=$value;?>" controls autoplay>
<source id="video<?=$value;?>" src="<?=$SITE_URL.$SUB ."/".$value;?>" type="video/mp4" />
</video>
<canvas id="thecanvas">
</canvas>
<div id="Imagecontainer"></div>
<img id="thumbnail_img" alt="Right click to save"/>
<?php
}
?>
<br/>
<?php
}
}
?> </div>
위 코드는 foreach 루프의 첫 번째 요소에 대해서만 반복됩니다. 다른 요소의 경우 때때로 첫 번째 요소의 값만 가져 오지만 때로는 짜내기도합니다. 각 루프에 대해서만 Windows로드 이벤트,이 스크립트를 다른 이벤트에 대해 실행하도록 만드는 방법을 실행합니다.아약스는 첫 번째 반복 만 수행합니다.
이 코드는 많은 코드를 통해 읽혀지며 많은 내용이 html입니다. 논리적이지 않은 (논평, 대부분의 html, 문제와 관련없는 php) 모든 내용을 잘라내어 문제를 보여주기 위해 최소한의 내용 만 포함한다면 훨씬 더 많은 것을 얻을 수 있습니다. 응답. – Hecksa
이 코드를 편집했습니다.이 부분을 확인하십시오. –
더 자세히 살펴 보지 않고서도 문제가'php' 루프 내에서'window.onload = function() {'라인에 있다고 확신합니다. 생성 된 HTML 코드는'window.onload'를 모두 덮어 쓰는 다중 스크립트 블록을 가지고 있으므로 마지막 블록 만 _win_이됩니다. –