Solved

PHP file_exists with wildcard

Posted on 2008-10-07
1
1,173 Views
Last Modified: 2013-12-12
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
Comment
Question by:fastfind1
1 Comment
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 22658513
You can try:
if (count(glob('/home/swipeweb/public_html/crm/cbacks/group/*.pdf')) > 0) {
...
}

Open in new window

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question