[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1211
  • Last Modified:

PHP file_exists with wildcard

I have a php script that works perfectly, IF there are PDF files in the directory.  IF there are PDF files in the directory, my script merges them all into one pdf, using pdftk copies the merged pdf to a new folder and deletes the old pdf's that were merged.

But if there are no PDF files and the script is run, then my script produces an error, because there are no files to merge.

I need to add an IF statement to first check and see if there are 1 or more files in the directory.  If yes, then run the script.  If no then don't run the script.  So I don't need to change the script, other than to somehow put it within an IF statement that first checks to see if at least one pdf file is in the /group directory.
<?php
 
//here is where the pdftk application merges all of the pdf files in the directory /home/swipeweb/public_html/crm/cbacks/group/.  The merged
//pdf is saved in the same directory as yes.pdf
 
passthru('/home/swipeweb/public_html/crm/cbacks/pdftk /home/swipeweb/public_html/crm/cbacks/group/*.pdf cat output /home/swipeweb/public_html/crm/cbacks/group/yes.pdf');
 
//the following code renames the yes.pdf file, copies it to a new directory, and deletes ALL pdf files in the /group directory
$time = date(DATE_RFC822);
$base5 = $mid . "_" . $time . ".pdf"; 
$newLocation2 = '/home/swipeweb/public_html/crm/cbacks/download/' . $base5;
$copy = '/home/swipeweb/public_html/crm/cbacks/group/yes.pdf' ;  		
copy($copy, $newLocation2);
$del = glob("/home/swipeweb/public_html/crm/cbacks/group/*.pdf");
foreach($del as $v) {
      unlink($v);
}
?>

Open in new window

0
fastfind1
Asked:
fastfind1
1 Solution
 
hernst42Commented:
You can try:
if (count(glob('/home/swipeweb/public_html/crm/cbacks/group/*.pdf')) > 0) {
...
}

Open in new window

0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now