3

PHP スクリプトを使用して PDF ファイルを作成し、ファイル名でフォルダーを検索したいと考えています。フォルダには PDF ファイルのみがあり、次のようになります。

注文番号 + お客様名 + 金額

200_Anton_60.pdf
201_Peter_40.pdf
202_Melanie_60.pdf

ファイル名の詳細:

(Integer, unique and autoincrement) _ (string variable) _ (integer variable).pdf

PDF ファイルを保存する前に確認が必要です。フォルダ内の既存のファイルを検索します。注文番号と顧客名が一致し、金額のみが異なる場合は、PDF ファイルをサブフォルダに移動します。

あなたが私を助けてくれることを願っています!

4

1 に答える 1

2

これを試して :

$dir = "your_dir";

$order_no = 300;
$cust_name = "ABC";
$amount = 200;

foreach(glob($dir . '/*.pdf') as $file) 
{ 
    $dot = strrpos($file, '.');
    $file_amt = substr($file, 0, $dot);
    $file_amt = substr($file_amt, strrpos($file_amt, '/') + 1);
    $us = strrpos($file, '_');
    $file = substr($file, 0, $us);
    $file = substr($file, strrpos($file, '/') + 1);
    if($file == $order_no."_".$cust_name)
    { 
        if($file_amt == $order_no."_".$cust_name."_".$amount)
        {
            //do nothing
        }
        else
        {
            //if order no. and name matches
        }
    }
    else
    {
        //save directly
    }
} 
于 2013-07-08T13:53:19.367 に答える