<?php
session_start();
include('config/connexionDB.php');
include('functions/search_user.php');
if (!isset($_SESSION['id'])){
header('Location: index.php');
exit;
}
// On récupère les informations de l'utilisateur connecté
$req = $DB->query("SELECT *
FROM posts
ORDER BY id ");
$req = $req->fetchAll();
?>`
<?php
foreach($req as $r){
$info = new SplFileInfo($r['fileNameNew']);
$extaudio = array('.mp3', '.flac');
$extimage = array('.png', '.jpg');
if($info = $extaudio){
?>
<div class="card" style="width: 45rem;">
<div class="card-body" align="center">
<h6 align="left"><?= $r['author'] ?></h6>
<?php echo"<audio src='uploads/".$r['fileNameNew']."' controls>;"; ?>
<h3><?= $r['content'] ?></h5>
<a href="#" class="btn btn-success">Like</a>
<a href="#" class="btn btn-danger">Dislike</a>
</div>
</div><br>
<?php
}elseif($info = $extimage){
?>
<div class="card" style="width: 45rem;">
<div class="card-body" align="center">
<h6 align="left"><?= $r['author'] ?></h6>
<h3><?= $r['content'] ?></h5>
<a href="#" class="btn btn-success">Like</a>
<a href="#" class="btn btn-danger">Dislike</a>
<?php echo "<img src='uploads/".$r['fileNameNew']."'>"; ?>
</div>
</div><br>
<?php
}
}
?>`
如何从文件夹中显示不同的文件(mp3,jpeg)[关闭]
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- dongzha3058 2018-10-22 10:04关注
A few things.
$info = $extimage
is wrong. Use==
for a comparison. Both in the if and the elseif.if($info == $extaudio){
A single equals assigns a value, ie.
$age = 40
sets the age to 40,$age == 40
returnstrue
orfalse
if $age does equal 40 or not.Secondly,
$info = new SplFileInfo($r['fileNameNew']);
.$info
is an object, so comparing them directly will always retirn false.http://php.net/manual/en/class.splfileinfo.php
Instead, get the file extension and check if it is in your array.
http://php.net/manual/en/splfileinfo.getextension.php
if(in_array($info->getExtension(), $extaudio)){
Hope this helps! Good luck
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 stm32开发clion时遇到的编译问题
- ¥15 lna设计 源简并电感型共源放大器
- ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
- ¥15 Vue3地图和异步函数使用
- ¥15 C++ yoloV5改写遇到的问题
- ¥20 win11修改中文用户名路径
- ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
- ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
- ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
- ¥15 帮我写一个c++工程