Solved

PHP file_exists with wildcard

Posted on 2008-10-07
1
1,171 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
phpmyadmin 3 33
.php tree directory? 5 57
php string masking 4 29
is this a cms? 8 36
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 …

864 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now