WebSite X5Help Center

 
David B.
David B.
User

PDF View (How do I allow User to select the file to view?)  en

Autor: David B.
Besucht 3244, Followers 2, Geteilt 0  

I have placed a PDF View object on a webpage. It works ok for the file that I specified but I would like to display all of the .PDF files in a specific directory and have the user select the one that they want to view.

How can I do this?

Gepostet am
45 ANTWORTEN - 1 KORREKT
John S.
John S.
User

Hello David

You could make a page with a text-object.

Then in the text-object you place a line for every file you want the user to see.

Each line could be with a name of the file and then a short description.

On the name you put a link to the file.

It would look something like this :

file01.pdf   This is a manual for the machine model 01

file02.pdf   This is a manual for the machine model 02

file03.pdf   This is a manual for the machine model 03

file04.pdf   This is a manual for the machine model 04

Then when a user click on the filename, the PDF-file will be shown.

This is the simplest method.

You could also use the PDF object several times.

Another method would be to have some code that would create a list with the content of the directory. The list should be created with a link. This would function much the same way as the method with the text-object - but here it would automatic include all pdf-files that you upload to the folder.

Another method could be to use a system for this.

There is the ADMIDIO system where you can create folders and upload files to these folders. Each folder can have its own settings - who have access to this folder ( public or only members or only members of certain groups )

What will be the right solution depends on how many files and should there be restricted access to some of the files.

Hope this inspires to a solution.

Kind regards

John S.

Mehr lesen
Gepostet am von John S.
David B.
David B.
User
Autor

Thanks John...

The .pdf's are continually updated with different filenames so I cannot list them inn a static list.

I could not find anything on the ADMIDIO site.

so...

"Another method would be to have some code that would create a list with the content of the directory. The list should be created with a link. This would function much the same way as the method with the text-object - but here it would automatic include all pdf-files that you upload to the folder"... seems like the best approach.

I am not sure how to do this... I am guessing that I would look for a Javascript code segment and somehow insert it into the Website 5X page... or... is there another way?

How do I insert Javascript code into a page?

Mehr lesen
Gepostet am von David B.
John S.
John S.
User

Hello David

I have taken something that listed png-files and changed it to show pdf-files. There is a little problem with the columns, but this is only to show a way for you.

You could make a php-file with the content later in this post.

The file should be located in the root of your site. It will look for PDF-files in the files folder.

The PDF-files will be shown as links you can click on and then the PDF-file is shown.

On a page you simply make a link to the php-file you create with the code.

Here is the code - tell if you have it to "function".

<?PHP
// Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.

// Edited by John S. 09-01-2018

function getFileList($dir)
{
// array to hold return value
$retval = array();

// add trailing slash if missing
if(substr($dir, -1) != "/") $dir .= "/";

// open pointer to directory and read list of files
$d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
while(false !== ($entry = $d->read())) {
// skip hidden files
if($entry[0] == ".") continue;
if(is_dir("$dir$entry")) {
$retval[] = array(
"name" => "$dir$entry/",
"type" => filetype("$dir$entry"),
"size" => 0,
"lastmod" => filemtime("$dir$entry")
);
} elseif(is_readable("$dir$entry")) {
$retval[] = array(
"name" => "$dir$entry",
"type" => mime_content_type("$dir$entry"),
"size" => filesize("$dir$entry"),
"lastmod" => filemtime("$dir$entry")
);
}
}
$d->close();

return $retval;
}
?>

<h1>Display PDF files as links in a TABLE</h1>

<table class="collapse" border="1">
<thead>
<tr><th></th><th>Name</th><th>Type</th><th>Size</th><th>Last Modified</th></tr>
</thead>
<tbody>
<?PHP
// output file list as table rows
$dirlist = getFileList("./files");
foreach($dirlist as $file) {
if($file['type'] != 'application/pdf') continue;
echo "<tr>\n";
echo "<td><a href=\"{$file['name']}\">",basename($file['name']),"</a></td>\n";
echo "<td>{$file['type']}</td>\n";
echo "<td>{$file['size']}</td>\n";
echo "<td>",date('r', $file['lastmod']),"</td>\n";
echo "</tr>\n";
}
?>

</tbody>
</table>

Mehr lesen
Gepostet am von John S.
David B.
David B.
User
Autor

Thanks John...

I really appreciate your help.

I will give it a try tomorrow or next day...

I'll let you know if I can make It work.

David

Mehr lesen
Gepostet am von David B.
John S.
John S.
User

Hello David

If you change line 44 to this : <tr><th>Name</th><th>Type</th><th>Size</th><th>Last Modified</th></tr>

then it should look better.

Mehr lesen
Gepostet am von John S.
John S.
John S.
User

Line 45

Mehr lesen
Gepostet am von John S.
John S.
John S.
User

Hello again David

I could not resist - I made a test myself : http://www.bramminginfo.dk/brm02/side-78.php

I made this page with 2 html-objects.

The upper object only has a function that steps 1 back in the tab history.

The lower object is an iframe that holds the php-file with the code.

When clicking one of the PDF-files, this will be shown in the iframe. When clicking "Go back" you will be back to the list.

If the list will contain many PDF-files there will come a scrollbar and you can then scroll up and down in the list.

I hope my posts is helpful for you.

Kind regards

John S.

Mehr lesen
Gepostet am von John S.
John S.
John S.
User

@ JJ. JUAG

Your php has more "finish" than my example. My example was a "first shot".

I think it could be a good idea if you would in your php-file put in some variables, so David, I, and potential other users could use this script as "standard".

The variables should be file-types to select on.

So people could easily make a list for only PDF or pdf

Or a list for : jpg,JPG,PNG,png, gif, GIF

Or whatever file type. The variable could be a string with the file-types.

And then ( maybe )  an easy way to set up which columns to show.

@David

JJ's php -file could as well be used to show in the Iframe.

Kind regards

John S.

Mehr lesen
Gepostet am von John S.
JJ. JUAG
JJ. JUAG
User

Yes, the php file is freely customizable to your needs.
Here it is optimized for the HP where it is in use. Especially with a special directory to make the project leaner, because the pdf-files are not integrated in the project.

JJ.

Mehr lesen
Gepostet am von JJ. JUAG
David B.
David B.
User
Autor

John S.

I created the .php file... copied it to the root of my site... placed a link on a page...

see attached file... no .pdf files are listed.... I copied some .pdf's to the /files Directory and also to the root.

Any idea why the files are not being listed?

Mehr lesen
Gepostet am von David B.
JJ. JUAG
JJ. JUAG
User

Test:

http://daveboomer2.com/PDFView.php

Result: 500 error

Internal Server Error 
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Show for the error into the log

if the php correct placed in / and to the directorie with the pdf-files ??

JJ.

Mehr lesen
Gepostet am von JJ. JUAG
John S.
John S.
User

Hello David

It seems that you have named the folder PDFfiles : It should be files

The place where the files reside, have to be the same as the name in this line :

$dirlist = getFileList("./files");

So - you could either change the name in the file to the name you have specified here :

Or - you could rename the foleder PDFFiles to files

or - if you already have a folder with the name files, you could copy some PDF's to it.

Hope you have it to function - it should function.

By the way - when you have it to function, you should change the line 45 - in the screenshot it seems that you have not done this yet.

Kind regards

John S.

Mehr lesen
Gepostet am von John S.
John S.
John S.
User

The line could be : $dirlist = getFileList("./PDFFiles");

I am not quite sure I understand JUAG's last post - using "my" script should not cause any error.

I have tested it, and it functions - it should also function on your server.

Please let us know if/when you have it to function.

Kind regrads

John S.

Mehr lesen
Gepostet am von John S.
John S.
John S.
User

Hello David

Maybe you are testing both solutions.

The solution I suggest, will function if you change the foldername or the foldername in the script. And then change the issue in line 45.

You should try this - it will function - then you could later try other options.

But it is up to you. I personally would like to know if my proposal functions ( of course it does ) or what could be wrong.

As I have taken my time to help you, I will ask if you will take your time to find out if my suggestion is work-able at you, or not.

If not - I shall not bother you any more.

Kind regards

John S.

Mehr lesen
Gepostet am von John S.
David B.
David B.
User
Autor

Thanks John!

Very sorry for the delay... a family matter took me away from my computer for a few days.

YOUR SOLUTION WORKED!!!

Thanks you !!! :-)

David

Mehr lesen
Gepostet am von David B.
David B.
David B.
User
Autor

oops... I spoke too soon.

It displays an empty popup then after a few seconds displays an error msg.

The message has no number code, just a server error. It looks like it can't find any files but I have put .PDF files in both a 'Files' and a 'PFDReports' folder in the root.

The .PHP file is exactly as you provided... I made no changes to it.

Mehr lesen
Gepostet am von David B.
John S.
John S.
User

Hello david

I see you spell files as Files.

It has to be exactly like this : $dirlist = getFileList("./files");

Here is used no capital letters. Try to rename your directory, or change the folder name in the php-file.

Even if I in a post like this, I make a misspelling, most people can understand the meaning anyway - PHP accepts NO misspelling at all.

If you want me to, I can supply you with a version of the php-script, where the line 45 is corrected. It will be copy of the file used in the example here : http://www.bramminginfo.dk/brm02/side-78.php

If you want me to, I can set the directory to a name you choose - you just have to tell the correct name of the folder to be searched.

Please tell if you have it to function when correcting the foldername and/or if you want me to supply you with a file.

Kind regards

John S.

Mehr lesen
Gepostet am von John S.
David B.
David B.
User
Autor

Thank you for your continued help... I really appreciate it.

When I said 'I have put .PDF files in both a 'Files' and a 'PFDReports' folder in the root'' I meant to write: 'I have put .PDF files in both a 'files' and a 'PFDReports' folder in the root of the website (httpdocs)'

So.. I changed the .phpcode to  $dirlist = getFileList("./httpdocs/files");

This is an improvement... I get the title: "Display PDF Files As Links In A TABLE"

and the table column headers...

but there are no files listed and I get the following error: getFileList: Failed opening directory ./httpdocs/files/ for reading

I changed the .php to $dirlist = getFileList("./httpdocs/PDFReports");

and got the error: getFileList: Failed opening directory ./httpdocs/PDFReports/ for reading

Mehr lesen
Gepostet am von David B.
JJ. JUAG
JJ. JUAG
User

httpdocs are the root directory for the homepage. Make the Test for /PDFREports/ or /files  (with or without / at the end)

Failed opening directory ./httpdocs/files/ for reading   for missing directory into the Homepage !!

JJ.

Mehr lesen
Gepostet am von JJ. JUAG
David B.
David B.
User
Autor

Thanks JJ...

I have been trying ./PDFReports and ./files but they did not work at all... a blank popup was displayed, followed in a few seconds by an error message (see attached file above). 

That's why I tried ./httpdocs/files and ./httpdocs/PDFReports which worked better insofar instead of a blank popup followed by an error, I got a popup with the correct title and column headers for the pfd files... but no files were displayed even though I have copied .pdf files to both directories.

Mehr lesen
Gepostet am von David B.
John S.
John S.
User

Hello David

I have a screenshot from one of my sites here :

Here you see the root-folder.

The upper sub-folders is created by X5. You also see some pages - they are in the root folder.

Then you have some subfolders:

admin ( you should also have such a folder ) 

cart

And then you have a sub-folder named : files

I also have a subfolder named : Ledelsnyt

And also a subfolder : pdffiler

See what I mean ????

Standing in the root, you create a sub-folder, and in this folder put the pdf-files.

Let's say you create a folder ( subfolder ) named files - then the line in the file should look like this :

$dirlist = getFileList("./files");

If you give a link to one of your pdf-files, then I can create the php-file to match exactly your need, and then post it here - if you want to.

Kind regards

John S. 

Mehr lesen
Gepostet am von John S.
David B.
David B.
User
Autor

I have already created the directories as you outline... see below and attached.

Mehr lesen
Gepostet am von David B.
John S.
John S.
User

Hello David

It seems to be OK - do you have the PHP-file in the httpdocs folder.

The php-script should be located just one level up from the files-directory on the server.

It should function.

Attached you will find my copy of pdflist3.php - the same used in my example.

This should be placed in the folder      httpdocs     and the pdf-files should be in     httpdocs/files

Let us know how it goes.

Kind regards

John S.

Mehr lesen
Gepostet am von John S.
John S.
John S.
User

If it does not work - then please give a link to this testsite, so I can check if the files are located as they should.

If it works then shout hurray and let us know.

Mehr lesen
Gepostet am von John S.
David B.
David B.
User
Autor

Thanks John... sorry... still not working

I uploaded your pdflist.php(all lowercase) to the root of my website and changed the link to this file... not working :-(

I don't know what you mean by 'please give a link'  the website is daveboomer2.com

Mehr lesen
Gepostet am von David B.
John S.
John S.
User

Hello David

I first give you an example :

I have a site bramminginfo.dk

On this site I have made a testsite in a subfolder brm02

My testsite is : http://www.bramminginfo.dk/brm02

Could also be written : http://www.brm02.bramminginfo.dk

1 - My php-file is located here : http://www.bramminginfo.dk/brm02/pdflist3.php

My pdf-files for test  is located in a subfolder : files

2 - one of the pdf-files is : http://www.bramminginfo.dk/brm02/files/This%20is%20a%20pdf%20file%20test.pdf

I don't quite understand the locations for your site, but if you would give me a link to your php-file - like I have done in ( 1 )

And then a link to one of your pdf-files - like I have done in ( 2 ), then I think that things will be clearer for me, and hopefully I can then see what could be wrong.

Kind regards

John S.

Mehr lesen
Gepostet am von John S.
 ‪ KolAsim ‪ ‪
 ‪ KolAsim ‪ ‪
Moderator
Nutzer des Monats RU
David B.
Thanks John... sorry... still not working ... ...

(modified, simplified) - Put this attached PHP file in the same folder containing PDF files.
(read all the files in the folder)

directory_contents_k.php

www.yoursite/foldername/directory_contents_k.php

.

 (IT) - ciao

Mehr lesen
Gepostet am von  ‪ KolAsim ‪ ‪
John S.
John S.
User

Hello David

We are approaching the problem. 

I think you are doing it wrong. 

The first link http://daveboomer2.com/httpdocs/PDFView.php is not correct. Here the system cannot find the php-script.

In the second link http://daveboomer2.com/PDFView.php the php is found by the system.

It is OK - the script can be in the root-folder, but then we have to adjust the path to where the script should look for files.

I asked you if you would give a link to one of the PDF-files. I have a feeling, that their location is not exactly where it should be if your explanation is correct.

Please a link to one of the PDF's - then we take it from there.

Mehr lesen
Gepostet am von John S.
John S.
John S.
User

It should be a valid link. When you click the link you post, then the pdf should be shown when the link is clicked.

Mehr lesen
Gepostet am von John S.
John S.
John S.
User

Okay David

I tried myself with http://daveboomer2.com/files/Test%20Page.pdf

And this seemed to function.

We now need the file that I attached to a former post to be put in the root.

The link that functioned before does not function now (http://daveboomer2.com/PDFView.php )

But the file was placed the correct location - you have to place the php-file from me, in the root.

Of course you have to unpack the file.

When you place pdflist3.php in the root then it should function.

Again : please send me a link to the pdf-file in the root, so we can test that all functions.

Mehr lesen
Gepostet am von John S.
John S.
John S.
User

Correction : Again : please send me a link to the PHP-file in the root, so we can test that all functions.

Mehr lesen
Gepostet am von John S.
Georg V.
Georg V.
User

filenames with space should be avoided. That may be a cause something is going wrong. MAY BE

Mehr lesen
Gepostet am von Georg V.
David B.
David B.
User
Autor

? link to the phpfile in the root ?

http://daveboomer2.com/pdflist3.php exists... so does http://daveboomer2.com/PDFView.php

I can see them in my FileZilla window... but I get a document not found error

http://daveboomer2.com/httpdocs/pdflist3.php and http://daveboomer2.com/httpdocs/PDFView.php also exist... I can see them in FileZilla on the server... but I get a similar error

I called GoDaddy (the host service)... they checked and said that nothing is blocking the pages at the server end.

Mehr lesen
Gepostet am von David B.
David B.
David B.
User
Autor

I removed the space... no success

Mehr lesen
Gepostet am von David B.
David B.
David B.
User
Autor

Latest error:

Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.

Earlier I contacted GoDaddy, as indicated in earlier post.

Mehr lesen
Gepostet am von David B.
 ‪ KolAsim ‪ ‪
 ‪ KolAsim ‪ ‪
Moderator
Nutzer des Monats RU
David B.
... ... ... I uploaded KolAsim's file and tried that link I have tried http://daveboomer2.com/httpdocs/directory_contents_k.phphttp://daveboomer2.com/httpdocs/files/directory_contents_k.php and many other permutations and combinations

You did not follow the instructions. The PHP file is missing, which must be in the same folder as the files.
...!... Not Found - The requested document was not found on this server.
XXXXXXX

(IT) - Non hai seguito le istruzioni. Manca il file PHP, che deve trovarsi nella stessa cartella dei files.

.

ciao

.

Mehr lesen
Gepostet am von  ‪ KolAsim ‪ ‪
David B.
David B.
User
Autor

hmmm we are making progress :-)

The following works  http://daveboomer2.com/directory_contents_k.php

directory_contents_k.php is in the /httpdocs directory not the website root... so the server seems to assume that /httpdocs is the directory to look in for the specified file.

http://daveboomer2.com/PDFView.php and http://daveboomer2.com/pdflist3.php do not work.

KolAsim... I'm sorry... but I'm pretty sure that I followed your instructions... when the directory_contents_k.php file is in the /httpsdoc/files or the /httpdoc/PDFReports directory I get a "Not Found' error. 

Mehr lesen
Gepostet am von David B.
John S.
John S.
User

Hello David - I am stepping out of this thread.

Hope you have it to function

Kind regards

John S.

Mehr lesen
Gepostet am von John S.
David B.
David B.
User
Autor

John... thanks for your help, you have been terrific!

Thanks KolAsim your .php worked. I don't know enough about php programming to be able to understand why or even if John's code did not work.

Mehr lesen
Gepostet am von David B.