I have a folder which consists of .doc and .xls files..i want to search a particular file from a folder and display the contents using php code.how to do it?i am new to php
navi18
0
Newbie Poster
Recommended Answers
Jump to PostYou can use readdir to read a directory and then while you read it, you could stop reading it when (or if) you find the file you need.
For example:
Jump to PostYou could also use 'glob'. Check some recent threads on this forum, I remember contributing to a few just this year. Something like this maybe?
$results=glob("{*.doc,*.xls}",GLOB_BRACE); $search = $_GET['search']; $r = array_filter($results, function ($item) use ($search) { $fn = pathinfo($item, PATHINFO_FILENAME); return (stristr($fn, $search)); }); print_r($r);
All 5 Replies
minitauros
151
Junior Poster
Featured Poster
navi18
0
Newbie Poster
diafol
navi18
0
Newbie Poster
navi18
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.