Answer the question
In order to leave comments, you need to log in
How to determine the file format on the site and change the layout for it?
Hello, tell me a script that changes the code depending on the file extension.
For example, an image and video, or a sound file and an archive.
Something like
if ext .mp3
<audio src="name.mp3" controls></audio>
else
<a href="name.zip" download>Скачать файл</a>
Answer the question
In order to leave comments, you need to log in
$filename = 'file.mp3'; //сам файл
$format = pathinfo($filename, PATHINFO_EXTENSION); //определяем формат
//условия
if($format == 'mp3'){
echo '<audio src="'.$filename.'"></audio>'
}else if($format == 'mp4'){
echo '<video><source src="'.$filename.'" type="video/mp4"></video>'
}else if($format == 'jpg'){
echo '<img src="'.$filename.'">'
}else{
echo 'формат не найден'
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question