トップ 差分 一覧 ソース 検索 ヘルプ PDF RSS ログイン

PHPめも

アップロードファイルサイズ設定

1.php.iniを修正

$ diff php.ini.s php.ini
401c401
< memory_limit = 128M
---
> memory_limit = 500M
687c687
< post_max_size = 8M
---
> post_max_size = 500M
839c839
< upload_max_filesize = 2M
---
> upload_max_filesize = 500M
$

ヒアドキュメントの中に関数を書きたい時

https://pisuke-code.com/here-document-expand-expression/

ヒアドキュメント内では純粋な変数しか展開できません。普通の書き方ではクラス変数や関数あるいは式は書くことができません。解決策は渡された変数をただ単に返しているだけの関数の変数を作成します。

       public function getRepFile($repids){
           // 渡された変数を返す変数 ヒアドキュメントの中に関数を書きたい時の解決策
           $wrap = function( $expression ){
                 return $expression;                                                                                                                                                                               };

           $query = <<< End_Query
SELECT
   m.vchReportID
   ,m.vchReportName
   ,m.vchPdfName
   ,a.vchX
   ,a.vchY
   ,a.vchFontSize
   ,a.vchWidth
   ,a.vchHeight
   ,a.intAppSeq
FROM
   レポートリスト m
INNER JOIN レポート情報 a on
   a.vchReportID = m.vchReportID
   AND a.intAppSeq <> 0
WHERE
   m.vchReportID in ('{$wrap(implode("','",$repids))}')
ORDER BY m.intOrder,a.vchReportID,a.intAppSeq
End_Query;

           return $this->objDb->func_selectDb($query);
       }

PHPでZipArchiveを使ってディレクトリを丸ごと圧縮する

https://blog.ver001.com/php-zip-archive/

PHP公式マニュアルにもサンプルが掲載されているので、あらためて解説するまでもない気もしますが、ZipArchiveクラスはファイルやディレクトリを追加する関数は持っていても、ディレクトリを指定するだけで丸ごと圧縮してくれるような便利な機能は持っていないので、自前でディレクトリを走査してあげる必要があります。

zipSubという関数を再帰表現で呼び出し、子階層をどんどん掘って、じゃんじゃんファイルを追加しているだけ。

       //zipファイル作成 zip(対象フォルダー,zipファイル)                                                                                                                                                                                      function zip($path, $zipfile) {
           $za = new ZipArchive();
           $za->open($zipfile, ZIPARCHIVE::CREATE);
           $this->zipSub($za, $path);
           $za->close();
       }
       //フォルダーを再帰に検索しアーカイブする
       function zipSub($za, $path, $parentPath = '') {
           $dh = opendir($path);
           while (($entry = readdir($dh)) !== false) {
               if ($entry == '.' || $entry == '..') {
               } else {
                   $localPath = $parentPath.$entry;
                   $fullpath = $path.'/'.$entry;
                   if (is_file($fullpath)) {
                       $za->addFile($fullpath, $localPath);
                   } else if (is_dir($fullpath)) {
                       $za->addEmptyDir($localPath);
                       $this->zipSub($za, $fullpath, $localPath.'/');
                   }
               }
           }
           closedir($dh);
       }

PDF作成(PDFを元に項目を埋める)

   ///ybWebPDF_Exe.php
   //届書PDF作成とS3にアップロード
   //
   //PDF作成ライブラリの読み込み
   require_once('../tcpdf/tcpdf.php');
   require_once('../tcpdf/fpdi/autoload.php');

   //共通ライブラリの読み込み
   require_once('../php/ybCommon.php');
   require_once('../php/ybCommonDB.php');
   //ログ出力ライブラリの読み込み
   require_once('../php/ybLog.php');

   class ybWebPDF_Exe {

       private $objDb;
       private $objComDB;
       private $ctcd;
       private $pdf;
       private $outdir;
       private $outdirAtt;
       private $dir;
       private $pittariApiUrl;
       private $curlProxy;

       //コンストラクタ
       public function __construct() {
           $this->ctcd = func_getSession('ctcd');
           //DB接続用ライブラリのインスタンス作成
           $this->objDb = new ybDbLib($this->ctcd);
           $this->objComDB = new ybCommonDB($this->ctcd);

           $this->pdf = new setasign\Fpdi\Tcpdf\Fpdi();
           $this->pdf->setPrintHeader( false );
           $this->dir = 'C:/temp/';
           $this->pittariApiUrl = $this->objComDB->selectParameterCurrent('PITTARI_API_URL');
           $this->curlProxy = $this->objComDB->selectParameterCurrent('CURLOPT_PROXY');
       }

       public function makePDF($args) {
           $jsonData = func_json2Ary($args);
           //送信フォルダー作成
           $this->mkdir($jsonData);
           //PDF作成
           $this->editPDF($jsonData);

       }
       //送信フォルダー作成
       public function mkdir($jsonData){
           $this->outdir = $this->dir.$jsonData["ident"];
           $this->outdirAtt = $this->outdir.'/Attachment';
           if(!is_dir($this->outdirAtt)){
               mkdir($this->outdirAtt,0700,true);
           }
       }
       //PDF作成
       public function editPDF($jsonData){
           $repids = array_keys($jsonData['usrinfo'][11]);
           $rows = $this->getRepFile($repids);
           $source = '';
           foreach($rows as $row){
               if ($row['vchPdfName'] != $source){
                   $source = $row['vchPdfName'];
                   $this->setSourceFile($source);
               }
               $this->pdf_text($jsonData['usrinfo'][11][$row['vchReportID']][$row['intAppSeq'] - 1]
                           ,$row['vchFontSize']
                           ,$row['vchX']
                           ,$row['vchY']);
           }                                                                                                                                                                                                       if($source != ''){
               $this->pdf_Output($jsonData["ident"]);
           }
       }
       public function setSourceFile($source){
           $this->pdf->setSourceFile("../../pdf/$source");

           $this->pdf->AddPage('L');         // 向き L:横、P:縦
           $tpl = $this->pdf->importPage(1);
           $size = $this->pdf->useTemplate($tpl);
           //$this->pdf->AddPage($size['orientation']);         // 向き L:横、P:縦
           //$tpl = $this->pdf->importPage(1);
           //$size = $this->pdf->useTemplate($tpl);
       }
       public function pdf_text($val,$siz,$x,$y){
           $x /= 2.9;
           $y /= 2.9;
           $this->pdf->SetFont('kozminproregular', '', $siz);
           $this->pdf->Text($x, $y, $val);
       }
       public function pdf_Output($arg){
           //$this->pdf->Output(出力時のファイル名, 出力モード);
           $this->pdf->Output($this->outdirAtt."/".$arg.".pdf", "F");
       }