I am trying to come up with a php script that will find a pdf file in a folder and display the results. This is in my site only. I need also to be able to open the pdf. I have looked at swish-e, but that is too complicated for me and a lot more than I need. I don't need to search in mysql.
The file are in the root/files at the site. The reason for the search, there will be 100's of pdf files.
Any help would will be appreciated. I am a newbie.
dwhphp
find a pdf file
Moderator: General Moderators
Re: find a pdf file
So you're looking for a pdf with a specific filename? If you know the filename and the directory, you can simply use file_exists() (http://us.php.net/manual/en/function.file-exists.php) to determine if it exists. If you want to display all pdf files in a directory, you can use readdir() (http://php.net/manual/en/function.readdir.php). I'm not quite sure I know what you are trying to do.
The simplest way to display a pdf file is to link to it. All browsers should support rendering of pdf files, typically through a plug-in, which most browsers already have installed.
The simplest way to display a pdf file is to link to it. All browsers should support rendering of pdf files, typically through a plug-in, which most browsers already have installed.
Re: find a pdf file
You can view the list of pdf files. Imagine that there are 100's of files and you need to find a specific file.
How do I do this?
Thanks for your help.
How do I do this?
Thanks for your help.
Last edited by dwhphp on Thu Feb 02, 2012 7:53 pm, edited 2 times in total.
Re: find a pdf file
readdir() + preg_match() should do the trick.
Re: find a pdf file
First of all, I suggest that you remove the username/password info in your last post, a hacker reading this forum could easily do a lot of damage to your site!
You need to define "find a specific file" more clearly. Is the user going to know the filename? Do you want to do a keyword search? There must be several different ways to "find a specific file", depending on what you want the user to do. Perhaps you would allow the user to specify a partial filename, then, using readdir(), you could read all the filenames in the directory, but only add a filename to an array if it matched the user's input, using preg_match(). Then the resulting array could be sent to the browser as a Javascript array and displayed to the user similar to the way you displayed all pdf files, only it will presumably be a much smaller list, allowing the user to select which one to view. You would include logic in case no matches were found, to notify the user that no matches were found. This is more of a user interface design than a PHP issue.
You need to define "find a specific file" more clearly. Is the user going to know the filename? Do you want to do a keyword search? There must be several different ways to "find a specific file", depending on what you want the user to do. Perhaps you would allow the user to specify a partial filename, then, using readdir(), you could read all the filenames in the directory, but only add a filename to an array if it matched the user's input, using preg_match(). Then the resulting array could be sent to the browser as a Javascript array and displayed to the user similar to the way you displayed all pdf files, only it will presumably be a much smaller list, allowing the user to select which one to view. You would include logic in case no matches were found, to notify the user that no matches were found. This is more of a user interface design than a PHP issue.