?
Solved

Using PHP look through a directory of files and filter by 3-digit number

Posted on 2008-06-20
4
Medium Priority
?
205 Views
Last Modified: 2010-04-21
I need to be able to sort through a list of files that have a naming scheme like this.
example:
102.101_floorplan.pdf
102.105_floorplan.pdf
103.105_floorplan.pdf
etc.,.......

what is the easiest way to search through this list. Using the first 3-digit number, get the file names and output a link for download on my web page. I would need to filter the results so that if there were 10 floorplans for one property or 2 floorplans for another it wouldn't matter. It would just output what was filtered through. Any help is appreciated greatly.
0
Comment
Question by:adrake9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 21834235
Can go like this. Place the code in the file floor and directory where the pdf are stored and give the search as parameter id to get the list.

http://x/pdf/floors.php?id=101
$searchnumber = '101';
$searchnumber = $_GET['id'];
$dir = '.';
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if (substr($file,0,3) !== $searchnumber) {
                continue;
            }
            echo "<a href=\"$file\">$file</a>\n";
        }
        closedir($dh);
    }
}

Open in new window

0
 
LVL 2

Author Comment

by:adrake9
ID: 21834269
The variable that I'm passing from page to page is:
PropNum=101 the url looks like this "infosheet.php?PropNum=101"

Can this variable be placed into the $searchnumber variable and the script run from that?

-A
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 2000 total points
ID: 21834328
Yes replace
$searchnumber = $_GET['id'];
with
$searchnumber = $_GET['PropNum'];


$searchnumber = '101';
can be ignored, only used for internal testing
0
 
LVL 2

Author Closing Comment

by:adrake9
ID: 31469299
PERFECT. JUST PERFECT. Thank you. Wish I could grad A++, quick and very helpful!
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

752 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