2012-10-14 27 views
0

我想支票夾,如果它包含PDF就會去其他的過程中,如果不包含PDF,它會跳過過程。 下面的代碼:檢查文件,如果不包含PDF它會跳過下一道工序

<?php 
set_time_limit(0); 
$savePath = 'D:/AppServ/www/aca/'; 

$dir  = opendir($savePath); 
$check = glob($savePath.'*.pdf'); 
if($check === ''){ exit();} // if not found pdf don't do process below this 

// many other process below 
?> 

但過程中仍然運行,如何突破呢?謝謝:)

+0

請記住,使用「文件擴展名」,以確定文件的類型是非常80ish ... – arkascha

回答

0

glob返回時,有沒有匹配的空數組,但你正在測試它是否等於一個空字符串。檢查數組是否爲空。

0
<?php 
    set_time_limit(0); 
    $savePath = 'D:/AppServ/www/aca/'; 

    $dir  = opendir($savePath); 
    $check = glob($savePath.'*.pdf'); 
    if(empty($check)){ exit();} // if not found pdf don't do process below this 

    // many other process below 
?> 
0
if(!count($check)) 
    exit; 

你有一個字符串,它總是會返回false比較$check

相關問題