ขอcode ที่download ไฟล์ที่เก็บในFoder เเล้วมีpopup ให้Saveประเภทรูป,txt ได้ส่วนไฟล์อื่นsave ได้
if(isset($_GET['webboard_id']))
ตรงนี้เราส่งค่า id= มา เราต้องเปลี่ยนตรง Get ของเราให้เป็นแบบนี้ครับ
if(isset($_GET['id']))
Date :
2010-11-13 12:00:38
By :
deawx
ลอง
<?
ob_start();
if(isset($_GET['webboard_id']))
{
$link = mysql_connect("localhost","root","root");
mysql_select_db("webboard",$link);
$id = $_GET['webboard_id'];
$query = "select FilesName from board where id =$webboard_id";
$result = mysql_query($query) or die('Error, query failed');
list ($FilesName) = mysql_fetch_array($result);
if (file_exists('myfile/'.$FilesNmae))
{
ob_end_clean();
set_time_limit(0);
header("Content-Description: File Transfer");
header("Content-Type: application/force-download");
header('Content-Length: '.filesize('myfile/'.$FilesNmae));
header("Content-Disposition: attachment; FilesName=".$FilesName);
readfile("myfile/".$FilesName);
exit;
}
}
else
{
echo 'File not found.';
}
?>
ประวัติการแก้ไข 2010-11-13 12:04:31
Date :
2010-11-13 12:01:45
By :
pjgunner.com
ลองอิกที ส่งค่า webboard_id ไป
Code (PHP)
<td><a href="download.php?webboard_id=<?=$objResult["webboard_id"];?>"><?=$objResult["FilesName"];?></td>
ส่งค่าwebboard_id มาที่ download.php
Code (PHP)
<?
if(isset($_GET['webboard_id']))
{
$link = mysql_connect("localhost","root","root");
mysql_select_db("webboard",$link);
$webboard_id = $_GET['webboard_id'];
$query = "select FilesName from board where webboard_id =$webboard_id";
$result = mysql_query($query) or die('Error, query failed');
list ($FilesName) = mysql_fetch_array($result);
header("Content-Description: File Transfer");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; FilesName=".$FilesName);
@readfile("myfile/".$FilesName);
}
echo 'File not found.';
exit;
?>
มันกลับให้popupให้ดาวโหลดไฟล์ download.php ซะงั้น
Date :
2010-11-13 12:35:13
By :
51035354
Code (PHP)
ob_start();
if(isset($_GET['webboard_id']))
{
$link = mysql_connect("localhost","root","root");
mysql_select_db("webboard",$link);
$id = $_GET['webboard_id'];
$query = "select FilesName from board where id =$webboard_id";
$result = mysql_query($query) or die('Error, query failed');
list ($FilesName) = mysql_fetch_array($result);
if (file_exists('myfile/'.$FilesNmae))
{
ob_end_clean();
set_time_limit(0);
header("Content-Description: File Transfer");
header("Content-Type: application/force-download");
header('Content-Length: '.filesize('myfile/'.$FilesName));
header("Content-Disposition: attachment; FilesName=".$FilesName);
readfile("myfile/".$FilesName);
exit;
}
else
{
echo 'File not found: myfile/'.$FilesName;
}
}
Date :
2010-11-13 12:41:33
By :
pjgunner.com
ลองดูอีกทีคับ
Code (PHP)
ob_start();
if(isset($_GET['webboard_id']))
{
$link = mysql_connect("localhost","root","root");
mysql_select_db("webboard",$link);
$id = $_GET['webboard_id'];
$query = "select FilesName from board where id ={$id}";
$result = mysql_query($query) or die('Error, query failed');
list($fname) = mysql_fetch_array($result);
$fpath = 'myfile/'.$fname;
if ( ! empty($fname) AND file_exists($fpath))
{
ob_end_clean();
set_time_limit(0);
//header('Content-Type: '.mime_content_type($fpath));
header('Content-Length: '.filesize($fpath));
header('Content-Disposition: attachment; filename="'.basename($fpath).'"');
readfile($fpath);
exit;
}
else
{
echo 'File not found: '.$fpath;
}
}
ประวัติการแก้ไข 2010-11-13 13:27:23
Date :
2010-11-13 13:24:18
By :
pjgunner.com
Code (PHP)
<?php
if(isset($_GET['webboard_id'])) {
$link = mysql_connect("localhost","root","root");
mysql_select_db("webboard",$link);
$id = $_GET['webboard_id'];
$query = "select FilesName,id from board where id =$webboard_id";
$result = mysql_query($query) or die('Error, query failed');
$record = mysql_fetch_array($result);
$FilesName = $record['FilesName'];
header("Content-Description: File Transfer");
header("Content-Type: application/force-download");
header("Content-Disposition:attachment; filename=".$FilesName);
@readfile("myfile/".$FilesName);
}
echo"faild";
exit;
?>
ลองดูนะครับไม่รู้ได้รึเปล่า
Date :
2010-11-13 13:46:02
By :
adaaugusta
Load balance : Server 01