jakebur01 Posted March 30, 2008 Share Posted March 30, 2008 How could I have php pull pdf's with a certain name? Ex. If their policy number is 68402. And I have "58692.12-23-2007.documentname.pdf" , "68402.11-12-2007.documentname.pdf", etc... It would only pull the 68402.11-12-2007.documentname.pdf. I wanted it to seperate the policy number and date from the .pdf name then only display links to the .pdf's associated with their policy number. Thanks, Jake Quote Link to comment https://forums.phpfreaks.com/topic/98579-viewing-pdfs/ Share on other sites More sharing options...
GingerRobot Posted March 30, 2008 Share Posted March 30, 2008 The glob function allows you to search for filenames matching a pattern. Quote Link to comment https://forums.phpfreaks.com/topic/98579-viewing-pdfs/#findComment-504614 Share on other sites More sharing options...
jakebur01 Posted March 30, 2008 Author Share Posted March 30, 2008 how could I make it break off the policy number from the file name and search for .pdf's according to that using the function below? It would be the number in front of the first period. (Ex. 485743.documentname.pdf) function browsepdf(){ $pdffile=glob("printable/*.pdf"); rsort($pdffile); foreach($pdffile as $filename){ $filename=ltrim($filename, "printable/"); $filename=rtrim($filename, ".pdf"); $file=$filename; $datetime=strtotime($filename); $newdate=strtotime("+3 days",$datetime); $filenamedate=date("F d", $datetime); $filenamedate.=" - ".date("F d, Y", $newdate); echo "<option value='$file'>$filenamedate</option>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/98579-viewing-pdfs/#findComment-504624 Share on other sites More sharing options...
GingerRobot Posted March 30, 2008 Share Posted March 30, 2008 So you just want to return files with that policy number at the beginning? <?php function browsepdf($policy){ $pdffile=glob("printable/$policy*.pdf"); rsort($pdffile); foreach($pdffile as $filename){ $filename=ltrim($filename, "printable/"); $filename=rtrim($filename, ".pdf"); $file=$filename; $datetime=strtotime($filename); $newdate=strtotime("+3 days",$datetime); $filenamedate=date("F d", $datetime); $filenamedate.=" - ".date("F d, Y", $newdate); echo "<option value='$file'>$filenamedate</option>"; } } browsepdf(485743); ?> Quote Link to comment https://forums.phpfreaks.com/topic/98579-viewing-pdfs/#findComment-504633 Share on other sites More sharing options...
jakebur01 Posted March 30, 2008 Author Share Posted March 30, 2008 thank you! Quote Link to comment https://forums.phpfreaks.com/topic/98579-viewing-pdfs/#findComment-504638 Share on other sites More sharing options...
GingerRobot Posted March 30, 2008 Share Posted March 30, 2008 No problem - you'd done most of it! Quote Link to comment https://forums.phpfreaks.com/topic/98579-viewing-pdfs/#findComment-504642 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.