Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,028

HOME > PHP > PHP Forum > download..จะทำให้ user download ไฟล์ PDF หรือ .doc จะดึง link จาก db มาแสดงยังไงคะ



 

download..จะทำให้ user download ไฟล์ PDF หรือ .doc จะดึง link จาก db มาแสดงยังไงคะ

 



Topic : 026793



โพสกระทู้ ( 80 )
บทความ ( 0 )



สถานะออฟไลน์




จะทำให้ user download ไฟล์ PDF หรือ .doc จะดึง link จาก db มาแสดงยังไงคะ



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-04-29 02:15:34 By : pochiiez View : 2352 Reply : 3
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

PHP PDF - MySQL Export to PDF
<html>
<head>
<title>ThaiCreate.Com PHP PDF</title>
</head>
<body>

<?php
require('fpdf.php');

class PDF extends FPDF
{
//Load data
function LoadData($file)
{
//Read file lines
$lines=file($file);
$data=array();
foreach($lines as $line)
$data[]=explode(';',chop($line));
return $data;
}

//Simple table
function BasicTable($header,$data)
{
//Header
$w=array(30,30,55,25,20,20);
//Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C');
$this->Ln();
//Data
foreach ($data as $eachResult)
{
$this->Cell(30,6,$eachResult["CustomerID"],1);
$this->Cell(30,6,$eachResult["Name"],1);
$this->Cell(55,6,$eachResult["Email"],1);
$this->Cell(25,6,$eachResult["CountryCode"],1,0,'C');
$this->Cell(20,6,$eachResult["Budget"],1);
$this->Cell(20,6,$eachResult["Budget"],1);
$this->Ln();
}
}

//Better table
function ImprovedTable($header,$data)
{
//Column widths
$w=array(20,30,55,25,25,25);
//Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C');
$this->Ln();
//Data

foreach ($data as $eachResult)
{
$this->Cell(20,6,$eachResult["CustomerID"],1);
$this->Cell(30,6,$eachResult["Name"],1);
$this->Cell(55,6,$eachResult["Email"],1);
$this->Cell(25,6,$eachResult["CountryCode"],1,0,'C');
$this->Cell(25,6,number_format($eachResult["Budget"],2),1,0,'R');
$this->Cell(25,6,number_format($eachResult["Budget"],2),1,0,'R');
$this->Ln();
}





//Closure line
$this->Cell(array_sum($w),0,'','T');
}

//Colored table
function FancyTable($header,$data)
{
//Colors, line width and bold font
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
//Header
$w=array(20,30,55,25,25,25);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
$this->Ln();
//Color and font restoration
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
//Data
$fill=false;
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
$this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
$this->Cell($w[2],6,$row[2],'LR',0,'L',$fill);
$this->Cell($w[3],6,$row[3],'LR',0,'C',$fill);
$this->Cell($w[4],6,number_format($row[4]),'LR',0,'R',$fill);
$this->Cell($w[5],6,number_format($row[5]),'LR',0,'R',$fill);
$this->Ln();
$fill=!$fill;
}
$this->Cell(array_sum($w),0,'','T');
}
}

$pdf=new PDF();
//Column titles
$header=array('CustomerID','Name','Email','Country Code','Budget','Used');
//Data loading

//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer";
$objQuery = mysql_query($strSQL);
$resultData = array();
for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
$result = mysql_fetch_array($objQuery);
array_push($resultData,$result);
}
//************************//



$pdf->SetFont('Arial','',10);

//*** Table 1 ***//
$pdf->AddPage();
$pdf->Image('logo.png',80,8,33);
$pdf->Ln(35);
$pdf->BasicTable($header,$resultData);

//*** Table 2 ***//
$pdf->AddPage();
$pdf->Image('logo.png',80,8,33);
$pdf->Ln(35);
$pdf->ImprovedTable($header,$resultData);

//*** Table 3 ***//
$pdf->AddPage();
$pdf->Image('logo.png',80,8,33);
$pdf->Ln(35);
$pdf->FancyTable($header,$resultData);

$pdf->Output("MyPDF/MyPDF.pdf","F");
?>

PDF Created Click <a href="MyPDF/MyPDF.pdf">here</a> to Download
</body>
</html>


PHP Word header("Content-type: application/vnd.ms-word");
<?
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; filename=testing.doc");
?>
<html>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["CustomerID"];?></div></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><div align="center"><?=$objResult["CountryCode"];?></div></td>
<td align="right"><?=$objResult["Budget"];?></td>
<td align="right"><?=$objResult["Used"];?></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
</body>
</html>


PHP Word (Word.Application) & PHP PDF Function






Date : 2009-04-29 06:49:35 By : webmaster
 


 

No. 2



โพสกระทู้ ( 80 )
บทความ ( 0 )



สถานะออฟไลน์


คุณ MR.WIN ช่วยอธิบายโค้ดพวกนี้ให้ฟังทีละส่วนๆ ได้ไหมคะไม่รู้เรื่องเลยค่ะ เลยเอามาประยุกต์ใช้ไม่ได้ รบกวนหน่อยนะคะ อีกนิดนึงนะคะ แล้วถ้าเราจะอัพโหลดไฟล์ .pdf หรือ .doc จะใช้ browse เหมือนเวลาอัพโหลดภาพได้ไหมคะ แล้วเวลาเก็บลงฐานข้อมูลจะใช้เป็นชนิด
อะไรคะ แล้วถ้าจะเก็บเป็น path ต้องทำไงบ้างคะ ขอบคุณจิงๆค่ะ
Date : 2009-04-29 22:25:14 By : pochiiez
 

 

No. 3



โพสกระทู้ ( 80 )
บทความ ( 0 )



สถานะออฟไลน์


ที่จิงไม่ได้ต้องการ export ออกมาในรูปแบบ doc หรือ pdf ค่ะ ที่ต้องการคือ upload ไฟล์ pdf หรือ doc ไปเก็บใน db แล้ว ดึงจาก db มาแสดงเพื่อดาวน์โหลด (คือ ให้ user กดคำว่า download เพื่อจะ save หรือ open เอกสาร doc หรือ pdf นั้นๆ อ่ะค่ะ) ขอโทษนะคะที่ตอนแรกไม่ได้อธิบายให้ชัดเจน ทำให้เสียเวลา ช่วยหน่อยนะคะ ขอบคุณค่ะ
Date : 2009-04-29 22:41:42 By : pochiiez
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : download..จะทำให้ user download ไฟล์ PDF หรือ .doc จะดึง link จาก db มาแสดงยังไงคะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่