doutang7383 2017-03-01 15:39
浏览 415

无法加载资源:net :: ERR_CONTENT_LENGTH_MISMATCH(php error)

I'm having two issues, one being that I can't loop songs (I tried in the audio tag in the HTML), and two being: Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH.

Misc info: The files are hosted on a cPanel. I also have other javascript files in the HTML file that the audio tags rest in, sometimes when I reload it the error has issues with the javascript. CSS, PHP, and JS files are also called within the same HTML file (if it matters) Also everything is being transferred over HTTPS.

What I'm trying to accomplish is playing music on a webpage using a PHP script. This script pulls mp3, mp4, and m4a files from a directory without having to draw an array for convenience. My friend made me this PHP script but we can't seem to figure out the issues so I'm asking for help here because I don't fully understand PHP yet.

HTML code:

<audio autoplay="" loop="" preload="auto" id="music" src="">
<script type="text/javascript">
var audio = document.currentScript.parentElement;
audio.volume = 0.1;

PHP file:

$list = new RecursiveDirectoryIterator(__DIR__);
$filetypes = array('mp3', 'mp4', 'm4a');
$files = array();
foreach(new RecursiveIteratorIterator($list) as $file) {
if (in_array(strtolower(array_pop(explode('.', $file))), $filetypes))
$files[] = $file;
$rand = $files[array_rand($files, 1)];
header('Content-Disposition: filename="'.basename($rand).'"');
header('Content-length: '.filesize($rand));

I've tested this in Firefox and I don't get this error: ( Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH ) and says at my file that is the issue. But the audio will also not loop. My friend has also tested this in Brave, and his version of Chrome but in my version of Chrome I get this issue.

I've asked a few people already and they can't seem to figure out why this is not working. I've looked in a few posts on here about similar issues and can't seem to fix it off of their suggestions.

I'm a bit of a noobie at PHP so if you can help guide me on how to fix it like where to add, replace, or delete code please tell me where.

Thanks for your time, hope we can get this to work.

  • 写回答

1条回答 默认 最新


      相关推荐 更多相似问题


      • ¥15 ubuntu18.04 tty报错&tty界面su/sudo命令无法执行,如何解决?
      • ¥20 关于c语言网络编程,实现传文件和即时聊天
      • ¥20 下面的压缩方法是否可行
      • ¥15 结构体数组读取文件信息失败,读取不了
      • ¥15 kaldi thchs30 训练遇到问题
      • ¥15 shellter无法使用,如何解决?(操作系统-kali)
      • ¥15 matlab动态模态分解程序
      • ¥60 关于渗透及远控的几个问题
      • ¥15 python文本词汇出现次数统计
      • ¥15 使用按键和串口,记录按键在不消抖的情况下触发的次数