Home > Article > Backend Development > How to add a music player to a php web page
How to add a music player to a php web page: 1. Define the mp3 file path on a disk; 2. Read the file size; 3. Set the media type of the file header; 4. Read the file.
The operating environment of this article: Windows 7 system, PHP version 7.4, DELL G3 computer
How to add a music player to the php webpage?
Add music playback code to the PHP web page
Define the mp3 file path under a disk, such as under d:/music
Read file size
Set the media type of the file header
Read file
<?php $path="d://music/"; $filesize=filesize($path.$file_name); header("Content-type:audio/mpeg"); header("Content-length:$filesize"); readfile($paht.$file_name); ?>
Play:
<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" width=300 height=300 hspace="0" vspace="0" align="top" id="MediaPlayer1" style="LEFT: 0px; TOP: 0px"> <param name="_ExtentX" value="5556"> <param name="ShowStatusBar" value="-1"> <param name="_ExtentY" value="1588"> <param name="AUTOSTART" value="-1"> <param name="SHUFFLE" value="0"> <param name="PREFETCH" value="0"> <param name="NOLABELS" value="0"> <param name="SRC" value="fileselect?file=曹操.mp3"> <param name="CONTROLS" value="Imagewindow,StatusBar,ControlPanel"> <param name="CONSOLE" value="RAPLAYER"> <param name="LOOP" value="0"> <param name="NUMLOOP" value="0"> <param name="CENTER" value="0"> <param name="MAINTAINASPECT" value="0"> <param name="BACKGROUNDCOLOR" value="#000000"> </object>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to add a music player to a php web page. For more information, please follow other related articles on the PHP Chinese website!