Executable to open a file

sonarman

New Member
Credits
43
I'm new here and have not used Unix/Linux in over 20 years, so here is what I want to do.
I am using cPanel Linux to host my website and the users will be PC's, Mac's etc.

I have a directory, D1, called Newsletters. In Newsletters is another directory, D2, called Previous Newsletters.
I want to select a executable file in D1 that opens a "PDF" file in D2.
This happens from a web browser.

How do I create the executable with the appropriate commands?
UPDATE
After a reply with some suggestions, I decided this is is not the way to do what I need. I will do it in a combination of html and JS or php.

Sonarman
 
Last edited:


stan

Well-Known Member
Credits
4,577
I'm new here and have not used Unix/Linux in over 20 years, so here is what I want to do.
I am using cPanel Linux to host my website and the users will be PC's, Mac's etc.
Welcome! Let's start with correcting your terminology. cPanel is not Linux. cPanel is a tool, an application, that controls the features of your server. Your server may be Linux, such as Ubuntu, Debian, CentOS, or other popular Linux server distribution. But it doesn't have to be Linux... the server could be anything.


I want to select a executable file in D1 that opens a "PDF" file in D2.
This happens from a web browser.
You could create executable Java script code, but there is no need for that. All you need to open a PDF is a hyperlink to the PDF. Most browsers will open a PDF with a built-in viewer or call the default viewer of the computer to open it. If the page being viewed is in D1, then that page's HTML code would include something like:

<a href="./D2/pdf-to-open.pdf">Click here to open PDF</a>

The "./D2/" is a relative path to the file, since you said the D2 folder is inside of D1 folder. You could also link with an absolute path instead. That would look something like:

<a href="http://your-website.com/D1/D2/pdf-to-open.pdf">Click here to open PDF</a>

You may need some tutoring on HTML coding. The web is loaded full with such tutorials.
 
Last edited:

sonarman

New Member
Credits
43
Welcome! Let's start with correcting your terminology. cPanel is not Linux. cPanel is a tool, an application, that controls the features of your server. Your server may be Linux, such as Ubuntu, Debian, CentOS, or other popular Linux server distribution. But it doesn't have to be Linux... the server could be anything.



You could create executable Java script code, but there is no need for that. All you need to open a PDF is a hyperlink to the PDF. Most browsers will open a PDF with a built-in viewer or call the default viewer of the computer to open it. If the page being viewed is in D1, then that page's HTML code would include something like:

<a href="./D2/pdf-to-open.pdf">Click here to open PDF</a>

The "./D2/" is a relative path to the file, since you said the D2 folder is inside of D1 folder. You could also link with an absolute path instead. That would look something like:

<a href="http://your-website.com/D2/pdf-to-open.pdf">Click here to open PDF</a>

You may need some tutorials on HTML coding. The web is loaded full with such tutorials.
I understand the cPanel reference, thanks.

I also understand the html part. I have that all working for normal stuff. BUT
What I do is provide a link to my users that opens the "D1" directory. In D1, are some help files and several directories. One is "D2" in D2 are multiple newsletter "pdf' files. In D2 I want to ref a specific pdf from a link in D1.

Thanks
Sonarman
 
Last edited:

stan

Well-Known Member
Credits
4,577
I also understand the html part. I have that all working for normal stuff.
Linking to a PDF is usually normal stuff too. Not sure what I'm missing.


What I do is provide a link to my users that opens the "D1" directory.
Does your link go to a html file? Or does it actually open a directory and show a list of files? Many servers will not allow you to show a raw list of files (and other directories), but some servers will allow this. I think it's not allowed for probably good reasons. It's generally better practice to have an index.html file in each directory to show users the contents. It's basically a "Table of Contents" for each directory, and a guide for usage.


One is "D2" in D2 are multiple newsletter "pdf' files. In D2 I want to ref a specific pdf from a link in D1.
So, I am guessing now that your D1 is a raw directory listing, and not using an index.html (or other html file) to list the contents, as I just described above. And if true, this is a good example why it is better practice to use a html file instead. I'm not a Java (or other) programmer, so I do not know if you can create some kind of "executable" file to link to the pdf in your D2 directory. Maybe others can give you more information about that. Or you could just copy the D2 pdf into D1 where it would show in the raw listing, if that's what you're doing.

But this should all be very simply done with HTML and using a hyperlink, just as I described before. I used to maintain many years of newsletters for an organization too, so I have a little bit of a clue on this. With a html file in D1, you could link to the pdf in D2.... but it might be better to link to another html file in D2. That D2 html file (index.html or something else) could give your users a clickable link to every edition of your previous newsletter. The D1 html file could also provide all the clickable links to open the current years newsletters (and any other files you want to share, like membership application for example) and then link to the D2 html file to show previous years newsletters.

I'm guessing again that the D2 pdf you want to link to will be a listing of those previous newsletters.... yes? If true, that pdf would need to have clickable links, which you can do. But you could do the same thing for a D1 pdf to show the contents instead of a raw directory listing, and have a clickable link to the D2 pdf as well.

So, if I'm way off base, let me know and I'll be glad to try again to understand your situation. But I really think simple HTML is the way to go to share your files with your users.
 
Last edited:

sonarman

New Member
Credits
43
Linking to a PDF is usually normal stuff too. Not sure what I'm missing.



Does your link go to a html file? Or does it actually open a directory and show a list of files? Many servers will not allow you to show a raw list of files (and other directories), but some servers will allow this. I think it's not allowed for probably good reasons. It's generally better practice to have an index.html file in each directory to show users the contents. It's basically a "Table of Contents" for each directory, and a guide for usage.



So, I am guessing now that your D1 is a raw directory listing, and not using an index.html (or other html file) to list the contents, as I just described above. And if true, this is a good example why it is better practice to use a html file instead. I'm not a Java (or other) programmer, so I do not know if you can create some kind of "executable" file to link to the pdf in your D2 directory. Maybe others can give you more information about that. Or you could just copy the D2 pdf into D1 where it would show in the raw listing, if that's what you're doing.

But this should all be very simply done with HTML and using a hyperlink, just as I described before. I used to maintain many years of newsletters for an organization too, so I have a little bit of a clue on this. With a html file in D1, you could link to the pdf in D2.... but it might be better to link to another html file in D2. That D2 html file (index.html or something else) could give your users a clickable link to every edition of your previous newsletter. The D1 html file could also provide all the clickable links to open the current years newsletters (and any other files you want to share, like membership application for example) and then link to the D2 html file to show previous years newsletters.

I'm guessing again that the D2 pdf you want to link to will be a listing of those previous newsletters.... yes? If true, that pdf would need to have clickable links, which you can do. But you could do the same thing for a D1 pdf to show the contents instead of a raw directory listing, and have a clickable link to the D2 pdf as well.

So, if I'm way off base, let me know and I'll be glad to try again to understand your situation. But I really think simple HTML is the way to go to share your files with your users.
Not far. My fault. The link to the D1 directory runs an index.php to provide the directory listing. The D2 dir also runs an index.php for its listing. An html method is going to prove to be the way. I’m setting up a web page that will open the wanted php file automatically when loaded, in the browser. Closing the php will take the user back to the D1 listing.

This exercise is for a website of a US Navy ship reunion association. We are all “old,” the youngest being 67 and the oldest is a WWII veteran (95).
 

stan

Well-Known Member
Credits
4,577
Ah, okay sailor, thank you for your service! That explains your username pretty well. :) I'm only a wee bit younger, turning 64 this year, and was USAF 1978-82.

So, using PHP scripting language on your site may provide the method as you originally asked, but I'm still afraid that is beyond my abilities. And again, maybe some others can offer some ideas on that. @JasKinasis in one we often lean on for code help, but @f33dm3bits, @KGIII, @Tolkem, @jglen490, and @dos2unix will all be called by naming them so they can take a look and see if they can help further. They're all pretty knowledgeable, but I'm not sure exactly which have code skills. And your skills are now clearly more than I first guessed! :oops: Sorry about that.

But knowing the details better of what you're doing and the tools you're using will help everyone to try to give a more reasonable evaluation than my clumsy efforts. Good luck!
 

KGIII

Super Moderator
Staff member
Gold Supporter
Credits
15,231
I will say that it's generally considered bad form to open a PDF automatically, at least not without warning.

And, as @stan said, I'm not seeing anything here that can't be done with straight HTML. Judging by your verbiage, you're not using a CMS of any kind?
 

sonarman

New Member
Credits
43
Ah, okay sailor, thank you for your service! That explains your username pretty well. :) I'm only a wee bit younger, turning 64 this year, and was USAF 1978-82.

So, using PHP scripting language on your site may provide the method as you originally asked, but I'm still afraid that is beyond my abilities. And again, maybe some others can offer some ideas on that. @JasKinasis in one we often lean on for code help, but @f33dm3bits, @KGIII, @Tolkem, @jglen490, and @dos2unix will all be called by naming them so they can take a look and see if they can help further. They're all pretty knowledgeable, but I'm not sure exactly which have code skills. And your skills are now clearly more than I first guessed! :oops: Sorry about that.

But knowing the details better of what you're doing and the tools you're using will help everyone to try to give a more reasonable evaluation than my clumsy efforts. Good luck!
Air Force! My brother was retired 20 years from the USAF. So I don’t make as many of the expected jokes. He passed last week. I think I have things figured out
 

stan

Well-Known Member
Credits
4,577
I'm sorry for your loss. :( But I'm glad you have a plan going forward for the website. There's a lot of old timers here (some older than you), and we'll be glad to have you stick around. You can learn, or you can probably teach us a thing or two. :)

One of our bright stars is learning to program in C... at 86 years young. :cool::)
(Yeah, I'm braggin' on you Charlie! @70 Tango Charlie!)
 
Last edited:

sonarman

New Member
Credits
43
I'm sorry for your loss. :( But I'm glad you have a plan going forward for the website. There's a lot of old timers here (some older than you), and we'll be glad to have you stick around. You can learn, or you can probably teach us a thing or two. :)

One of our bright stars is learning to program in C... at 86 years young. :cool::)
(Yeah, I'm braggin' on you Charlie! @70 Tango Charlie!)
Will do. Thank..
Sonarman out.
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Staff online

Members online


Top