:::

8-3 /pdf.php (多檔下載版)

<?php
include_once "header.php";

mk_pdf(111);
mk_pdf(112);
mk_pdf(113);

$dir_name = "phone_book";
$filename = "my_data.zip";

//---------------底下不用改-------------------//
$zip_dir = XOOPS_ROOT_PATH . "/uploads/{$dir_name}";
$file = XOOPS_ROOT_PATH . "/uploads/{$filename}";
$file_url = XOOPS_URL . "/uploads/{$filename}";
mk_dir($zip_dir);

if (file_exists($file)) {
    unlink($file);
}

$msg = shell_exec("zip -r -j $file $zipdir");

if (file_exists($file)) {
    header("location: {$file_url}");
} else {
    include_once 'class/pclzip.lib.php';
    $zipfile = new PclZip($file);
    $v_list  = $zipfile->create($zip_dir , PCLZIP_OPT_REMOVE_PATH, $zip_dir);

    if ($v_list == 0) {
        die("Error : " . $zipfile->errorInfo(true));
    } else {
        header("location: {$file_url}");
    }
}
delete_directory($zip_dir);
mk_dir($zip_dir);
exit;

function delete_directory($dirname)
{
    if (is_dir($dirname)) {
        $dir_handle = opendir($dirname);
    }

    if (!$dir_handle) {
        return false;
    }

    while ($file = readdir($dir_handle)) {
        if ($file != "." && $file != "..") {
            if (!is_dir($dirname . "/" . $file)) {
                unlink($dirname . "/" . $file);
            } else {
                delete_directory($dirname . '/' . $file);
            }

        }
    }
    closedir($dir_handle);
    rmdir($dirname);
    return true;
}



function mk_pdf($sn){
  global $xoopsDB;

  require_once(TADTOOLS_PATH.'/tcpdf/tcpdf.php');
  $pdf = new TCPDF("P");

  $pdf->setPrintHeader(true); //不要頁首
  $pdf->setPrintFooter(true); //不要頁尾
  $pdf->SetMargins(10, 25);
  $pdf->setHeaderMargin(5); //頁首上方與頁面頂端的距離
  $pdf->setFooterMargin(20); //頁尾上方與頁面尾端的距離

  $pdf->setHeaderData('pdf_logo.png', 50, '我的通訊錄', '常用電話', array(0, 0, 255), array(150, 150, 150));
  $pdf->setFooterData(array(0, 0, 0), array(0, 0, 0));
  $pdf->setHeaderFont(array('droidsansfallback', '', 12));
  $pdf->setFooterFont(array('droidsansfallback', '', 12));


  $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);  //設定自動分頁
  $pdf->setFontSubsetting(true); //產生字型子集(有用到的字才放到文件中)
  $pdf->SetFont('droidsansfallback', '', 10, '', true); //設定字型
  $pdf->AddPage(); //新增頁面


  $myts = MyTextSanitizer::getInstance();

  $sql = "select * from `" . $xoopsDB->prefix("phone_book") . "`
  where `sn` = '{$sn}' ";
  $result = $xoopsDB->query($sql) or web_error($sql);
  $all = $xoopsDB->fetchArray($result);

  //以下會產生這些變數: $sn, $cate_sn, $name, $birthday, $phone, $email, $zip, $county, $city, $addr, $note
  foreach ($all as $k => $v) {
      $$k = $v;
  }

  //取得分類資料(phone_book_cate)
  //$phone_book_cate_arr = get_phone_book_cate($cate_sn);

  //過濾讀出的變數值
  $name     = $myts->htmlSpecialChars($name);
  $birthday = $myts->htmlSpecialChars($birthday);
  $phone    = $myts->htmlSpecialChars($phone);
  $email    = $myts->htmlSpecialChars($email);
  $zip      = $myts->htmlSpecialChars($zip);
  $county   = $myts->htmlSpecialChars($county);
  $city     = $myts->htmlSpecialChars($city);
  $addr     = $myts->htmlSpecialChars($addr);
  $note     = $myts->displayTarea($note, 0, 1, 0, 1, 1);

  $pdf->SetFont('droidsansfallback', '', 36, '', true); //設定字型

  $pdf->Image(XOOPS_ROOT_PATH.'/uploads/photo.jpg', $x='', $y='', '80', '80', $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false, $alt=false, $altimgs=array());

  $pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
  $pdf->Cell(80, 80, $name, 1, 0, 'C','','','','','','B');
  $pdf->setTextShadow(array('enabled'=>false));

  $pdf->SetFont('droidsansfallback', '', 16, '', true); //設定字型

  $pdf->Cell(30, 20, '電話', 1, 0, 'C');
  $pdf->Cell(80, 20, $phone, 1, 1, 'C');

  //$pdf->Cell(80, 80, '', 0, 0, 'C');
  $pdf->SetX(90);
  $pdf->Cell(30, 20, '信箱', 1, 0, 'C');
  $pdf->Cell(80, 20, $email, 1, 1, 'C');

  $pdf->SetX(90);
  $pdf->Cell(30, 20, '生日', 1, 0, 'C');
  $pdf->Cell(80, 20, $birthday, 1, 1, 'C');

  $pdf->SetX(90);
  $pdf->Cell(30, 20, '地址', 1, 0, 'C');
  //$pdf->Cell(80, 20, "{$zip}{$county}{$city}{$addr}", 1, 1, 'C','','',1);
  $pdf->MultiCell(80, 20, "{$zip}{$county}{$city}{$addr}", 1, 'L');



  //PDF內容設定
  //$pdf->Output('通訊錄.pdf', 'I');
  // $pdf->Output('通訊錄.pdf', 'I');
  mk_dir(XOOPS_ROOT_PATH."/uploads/phone_book");
  $pdf->Output(XOOPS_ROOT_PATH."/uploads/phone_book/{$sn}.pdf", 'F');
}

 


:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.cp27.secserverpros.com%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1268%26tbsn%3D39

書籍目錄

展開 | 闔起

線上使用者

371人線上 (148人在瀏覽線上書籍)

會員: 0

訪客: 371

更多…