<p class="card-text">
<?php echo htmlentities($result2->PostBody);?>
</p>
<?php
if($result2->URL)
{
?>
<a href=""><?php echo htmlentities($result2->URL);?></a>
<?php } ?>
</div>
if(isset($_POST['share'])){
$gid=intval(openssl_decrypt($_GET['gid'],"AES-128-ECB", SECRETKEY));
$sid=$_SESSION['login'];
/*$vimage1=$_FILES["profile"]["name"];
move_uploaded_file($_FILES["profile"]["tmp_name"],"img/".$_FILES["profile"]["name"]);*/
$allowedExts = array("doc", "docx", "pdf", "gif", "jpeg", "jpg", "png", "pptx" ,"ppt","xlsx","xls");
if (($_FILES["file"]["type"] == "application/pdf") || ($_FILES["file"]["type"] == "application/msword") || ($_FILES["file"]["type"] == "application/vnd.ms-excel") ||($_FILES["file"]["type"] == "application/vnd.ms-powerpoint") || ($_FILES["file"]["type"]="application/vnd.openxmlformats-officedocument.wordprocessingml.document") ||($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.presentationml.presentation") || ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") || ($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/png") && ($_FILES["file"]["size"] < 20000000) && in_array(end(explode(".", $_FILES["file"]["name"])), $allowedExts))
{
$sql="insert into Posts (PostBody,URL, PostStatus,
PID, GroupID) values(:cbody,:vimage1, 1, :userid, :group)";
}
$query = $dbh->prepare($sql);
$query -> bindParam(':cbody',$_POST['post'], PDO::PARAM_STR);
$query->bindParam(':vimage1',$_FILES["file"]["name"],PDO::PARAM_STR);
$query-> bindParam(':userid',$sid, PDO::PARAM_INT);
$query-> bindParam(':group',$gid, PDO::PARAM_INT);
$query -> execute();
//$query->debugDumpParams();
}
我成功地将帖子和文件插入数据库,但是我的问题是如何检查上传的文件的类型以显示它,例如,如果我上传pdf文件,我需要在href标记中显示它,而如果我上传图像我需要在图片标签中显示