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

无法加载资源: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.

  • 写回答



      相关推荐 更多相似问题


      • ¥20 使用python中pandas进行数据分析
      • ¥15 关于#游戏程序#的问题:端 玩wy服务器10几分钟闪退一次没有任何提示,连启动器一起闪退 本人电脑5800h 3060 16运内 win11 求解答
      • ¥15 做一个手游私服需要什么条件?
      • ¥15 关于企业微信,调用官方 微盘api 时候access_token过期的问题?
      • ¥15 请问这个C语言代码的界面怎样修改
      • ¥15 QT for Android 开发的App后台切换后卡死,没有响应
      • ¥15 【Coppeliasim】利用remoteApi实现Coppeliasim与C++程序的数据通讯
      • ¥15 Spring Boot 服务迁移到 k8s , 配置文件 eureka.instance.prefer-ip-address = true,注册在 eureka 依然是服务名称
      • ¥15 No module named 'pyLDAvis'
      • ¥15 Microsoft.ReportViewer.WinForms 预览打印显示