以下是PHP在服务器端,得到数据后返回给浏览器的代码。
<?php header("Content-type:text/html;charset=utf-8"); $file_name=$_GET['fileName']; //用以解决中文不能显示出来的问题 $file_name=iconv("utf-8","gb2312",$file_name); $file_sub_path="/test/"; $file_path=$file_sub_path.$file_name; //首先要判断给定的文件存在与否 if(!file_exists($file_path)){ echo "没有该文件文件"; return ; } header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file_path)); header('Content-Transfer-Encoding: binary'); header('Expires: 1'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file_path)); ob_clean(); echo readfile($file_path); exit; ?>
<body> <form id="form1" runat="server"> <img src="http://111.121.22.141/download.php?fileName=/images/Chrysanthemum.jpg" style="max-width:90%" style="max-width:90%" alt="PHP从服务器请求完视频数据,如何显示?HTML5的video标签播放不了." ></img> <video width="320" height="240" controls="controls" preload="auto" autoplay="autoplay" > <source src="http://111.121.22.141/download.php?fileName=/video/traveltaipei.mp4" type="video/mp4"> </video> <audio controls="controls"> <source src="http://111.121.22.141/download.php?fileName=/voice/SleepAway.mp3"> </audio><!-- <embed widht="300" height="240" src="http://111.121.22.141/download.php?fileName=/video/traveltaipei.mp4" ></embed> --> </form></body>
技术大拿们,快来帮帮我吧!
大神们都跑哪H去了
不会吧,CSDN的大神们都不在吗?