Jump to content

PDF File Viewer/Search Bar


Seapoeschl

Recommended Posts

Hello,

 

I am currently working on an intranet website for the company I work at. I know more about Graphic Design then coding, so you can say I'm new to php code. The site is going to be used to let users log on and submit/view pdf files that are stored on the site. I have everything else created for the site(data form to build pdf, upload form, etc.), but I can't seem to figure out how to let the users view the files. I want to create a page where they can use a search bar to find the certain file that is stored in the files folder.

 

I have tried using the dir() and scandir() commands but they just list the files and are not able to open them. I don't want to hard code the .PDF files on a page since they will be constantly changing and being added. Is there a way to have these files be displayed (like a link) and have a search bar to be able to search through them to find the correct one needed?

 

Thanks,

 

Seattle

Link to comment
Share on other sites

This is the current code that I have for the display page.

 

<?php
//Open images directory
$dir = dir("TestUpload");

//List files in images directory
while (($file = $dir->read()) !== true)
{
echo "filename: " . $file . "<br />";
}

$dir->close();
?>

 

I attached a photo of what shows up in the browser. I want to be able to be able to click on the file name and have it open. Also have a search bar that will look through that Folder and find the file that matches the search.

post-134449-1348240358427_thumb.jpg

Link to comment
Share on other sites

I think I am a little bit confused about what you mean by wrapping with an html link. I have done it before where I would just hard code each file to the page by doing something like this:

<a href="pdf/Newsletter_Spring_2012.pdf" target="_blank">Pioneer Xpress Newsletter - Spring 2012</a>

 

How would I type the code so each file will have a link without having to hand code a new link every time a file is added?

Link to comment
Share on other sites

Unless I'm missing something..

 

echo "filename: <a href='$file'>" . $file . "</a><br />";

 

 

I tried this method, but I is not looking in the directory that it is pulling the file name from. The link is sending you to the same folder that the PHP file is stored, and looking for that file in there. I have these .PDF stored in a secure folder else where.

Link to comment
Share on other sites

I was able to get it to work when the folder is in the root folder of the PHP file. I have the folder that stores the .PDF files located outside the root folder. I will display the names of the files, but when I link them with the same path it wont open those files. Here is my code and paths(I tried with both / and \).

 

<?php
//Open images directory
$dir = dir("D:\TESTUP");

//List files in images directory
while (($file = $dir->read()) !== false)
{
echo "filename: <a href='D:\TESTUP\$file'>$file</a><br />";
}

$dir->close();
?>

 

PHP files are located in: D:\xampp\htdocs\sitea

 

.PDF files are located in: D:\TESTUP

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.