|
|
|
อยากให้ช่วยแนะหน่อยครับ ว่าแสดงข้อมูลเป็นภาพ หากชื่อไฟล์นั้นเป็นนามสกุล .gif, .png, .jpg จะแสดงเป็นรูปภาพ แต่หากไม่มี .gif, .png, .jpg จะขึ้นเป็นแค่ลิ้งดาวน์โหลดไฟล์นั้นๆ |
|
|
|
|
|
|
|
Code 2 (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Download</title>
<link rel="shortcut icon" href="images/hospital.png"/>
<link rel="stylesheet" href="jquery-ui.css" />
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="bootstrap/css/bootstrap-theme.min.css" />
<script src="jquery-1.8.2.js"></script>
<script src="jquery-ui.js"></script>
<script>
$(function() {
$( '#tabs' ).tabs();
});
</script>
<style>
body {
background: url('images/bg.jpg') top center ;
background-attachment:fixed;
background-size: 100%;
background-origin: content;
background-repeat: no-repeat;
}
</style>
</head>
<center>
<body>
<!------------------------------------------------------->
<?php
$con = mysqli_connect('localhost', 'root', '123456', 'dbboard');
$perpage = 5;
if (isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = 1;
}
$start = ($page - 1) * $perpage;
$sql = "select * from files limit {$start} , {$perpage} ";
$query = mysqli_query($con, $sql);
?>
<!-------------------------------------------------------->
<div><a href="page_admin.php"><img src='images/manage/1453217750_MB__back.png' width='40px' height='40px' style="float: right" /></a></div>
<br/><br/>
<form>
<div id='tabs' style="background-size: 100% 100%; width: 80%; ">
<ul>
<li><a href='#tab1'>View Download</a></li>
</ul>
<!------------------------ Add department ---------------------------->
<div id='tab1'>
<?
$db = new mysqli("localhost", "root", "123456", "dbboard");
if(mysqli_connect_errno()) die("Connect Failed! :" . mysqli_connect_error());
$db->set_charset("utf8");
$sql = $db->query("SELECT * FROM files");
echo "<table border = 1 cellpadding = 5 cellspacing = 1><tr>";
$rows = 0;
while($result = $sql->fetch_object()){
echo "<td>";
$rows++;
$type = substr($result->file_name,-3);
if($type == 'jpg' or $type == 'png' or $type == 'gif'){
?>
 <?php echo $result->file_id; ?>⟩
 <center><img src="fileUpload/<?php echo $result->file_name; ?>" /></center>
<br/>
<a href="fileUpload/download.php?pic=<?php echo $result->file_name; ?>"><img src='images/manage/1440760601_download.png' width='40px' height='40px' style="float: right" /></a>
<?
}else{
?>
 <?php echo $result->file_id; ?>⟩
 <a href="fileUpload/<?php echo $result->file_name; ?>"><?php echo $result->original_file_name; ?></a>
<?
}
echo"</td>";
if(($rows)%1==0)
{
echo"<tr></tr>";
}
}
echo"</tr></table>";
?>
<!--------------------------------------------------------------------------->
<?php while ($result = mysqli_fetch_assoc($query)) { ?>
<tr>
<td><?php echo $result['file_id']; ?></td>
<td><?php echo $result['file_name']; ?></td>
<td><?php echo $result['price']; ?></td>
</tr>
<?php } ?>
<?php
$sql2 = "select * from files ";
$query2 = mysqli_query($con, $sql2);
$total_record = mysqli_num_rows($query2);
$total_page = ceil($total_record / $perpage);
?>
<nav>
<ul class="pagination">
<li>
<a href="download_file_admin.php?page=1" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
<?php for($i=1;$i<=$total_page;$i++){ ?>
<li><a href="download_file_admin.php?page=<?php echo $i; ?>"><?php echo $i; ?></a></li>
<?php } ?>
<li>
<a href="download_file_admin.php?page=<?php echo $total_page;?>" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</ul>
</nav>
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-------------------------------------------------------------------->
</div>
</div>
</form>
</body>
</center>
</html>
เหตุที่นำมาดัดแปลง คืออยากให้มีฟังชันก์ แบ่งหน้า กับค้นหาข้อมูล
Tag : PHP
|
ประวัติการแก้ไข 2016-01-29 11:44:39
|
|
|
|
|
Date :
2016-01-29 11:43:37 |
By :
NuItMaster |
View :
776 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$path = "name.jpg";
$ext = pathinfo($path, PATHINFO_EXTENSION);
ได้ถค่า $ext แล้วก็น่าจะนำไป if ได้ไม่ยากครับ
|
|
|
|
|
Date :
2016-01-29 21:22:25 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|