The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

2 Pages V < 1 2  
Reply to this topicStart new topic
> How to code HTML download button where filename version will change
larry78723
post Mar 17 2020, 07:43 AM
Post #21


Member
***

Group: Members
Posts: 33
Joined: 5-March 20
Member No.: 27,220



QUOTE(CharlesEF @ Mar 16 2020, 11:35 PM) *

I didn't see this post before but here goes. In the PHP code $file2 is useless and should be removed, the entire line, because of the way href works it will NEVER work. You want to insert $file into the href attribute, like this:
CODE
<a href="<?php echo "/{$file}";?>" download>DOWNLOAD</a>
Notice the '/' at the start of the href. That represents the home directory. This means your download directory is located under your public_html directory.

Hope this helps, post back if you have any other questions.

Charles, I need some more help. I've changed to using a button.jpg and I'm getting a syntax error on the button. Here's the code as currently wriiten:
CODE

<?php
  $files = array();
  $files = glob('download/*.iso');
  $file = $files[count($files) - 1];
?>
    
<div id="download" class="filter">
    <div class="container">
       <div class="row">
            <div class="stylized">
                <h1>FoxClone Download Page</h1>
              
                <h3>Get the latest version of FoxClone </h3>
                    <a href="<?php echo "/{$file}";?>" <img src="images/button_get-the-app.png" alt="" width="104" height="40"></a>


I'd also like to know how I can check the members of the array(). I've heard about print_r($myarray) and var_dump($myarray) but have no idea how to insert it into my code so I can verify that the php code is working.

EDIT: I ran the code on my hosts server and I'm getting a 404 error with this information:
"This www.foxclone.com page can’t be found
No webpage was found for the web address: https://www.foxclone.com/<?php%20echo
HTTP ERROR 404"

I get the same error on my apache server. It appears that the "<?php echo "/{$file}";?>" isn't being translated. Is there a way to convert that to a standard variable before using it in the button?

Thanks again for all your help,
Larry

This post has been edited by larry78723: Mar 17 2020, 08:42 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Mar 17 2020, 11:15 AM
Post #22


.
********

Group: WDG Moderators
Posts: 8,632
Joined: 10-August 06
Member No.: 7



QUOTE(larry78723 @ Mar 17 2020, 01:43 PM) *

<a href="<?php echo "/{$file}";?>" <img

The link's start tag is missing its ">" character before the image. Try this instead:

CODE
<a href="<?php echo "/{$file}";?>"><img


QUOTE
I'd also like to know how I can check the members of the array(). I've heard about print_r($myarray) and var_dump($myarray) but have no idea how to insert it into my code so I can verify that the php code is working.

You can just insert it anywhere you want the result printed. It's a good idea to use a PRE element around it for better readability.

QUOTE
It appears that the "<?php echo "/{$file}";?>" isn't being translated.

Does the web page have a .php file extension? Usually, ordinary web pages with .html extensions won't run PHP (though that can be reconfigured).

QUOTE
Is there a way to convert that to a standard variable before using it in the button?

Not sure I understand, $file is a varaibale (never mind those curly characters around it). unsure.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 17 2020, 11:52 AM
Post #23


Programming Fanatic
********

Group: Members
Posts: 1,800
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



In case you haven't read this before, PHP will convert variables automatically when they are enclosed in double quotes. The curly braces are used to separate the variable from other text, sometimes PHP can't understand a variable name because of the other text. So, to avoid that problem I always use curly braces.

One suggestion, you should stick to 1 thing and get it working before you change to another. This way you can get an understanding of things. Then you can change to another.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
larry78723
post Mar 17 2020, 01:09 PM
Post #24


Member
***

Group: Members
Posts: 33
Joined: 5-March 20
Member No.: 27,220



QUOTE(Christian J @ Mar 17 2020, 12:15 PM) *

Does the web page have a .php file extension? Usually, ordinary web pages with .html extensions won't run PHP (though that can be reconfigured).


Christian, the web page is index.html. I did a 'Save As' index.php. When I opened it in the browser, it immediately downloaded itself but never opened in the browser. I removed all php and download code and tried again with the same result. I'm running a LAMP stack on this machine if that makes a difference. I think this might be a browser related problem. Looking into its' configuration now.

EDIT: It's definitely a browser problem. Any .php file I try to open does exactly the same thing.

This post has been edited by larry78723: Mar 17 2020, 01:42 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 17 2020, 02:47 PM
Post #25


Programming Fanatic
********

Group: Members
Posts: 1,800
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



How many browsers did you try it on? You should try it on several browsers, before thinking it's a browser problem. Below is a working example:
CODE
<?php
$files = array();
$files = glob("temp/*.txt");
$file = $files[count($files) - 1];
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Scan Dir, Pick Last File</title>
</head>
<body>
<a href="<?php echo("/{$file}");?>" alt="<?php echo("/{$file}");?>">Download the App</a>
</body>
</html>
I don't have any '.iso' files to test with so I used '.txt'. Be sure to change txt to iso in the PHP code. And, be sure to save the file as '.php'. Since I tested with text files I get the file loaded into the browser.

How does it work for you?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
larry78723
post Mar 17 2020, 04:32 PM
Post #26


Member
***

Group: Members
Posts: 33
Joined: 5-March 20
Member No.: 27,220



QUOTE(CharlesEF @ Mar 17 2020, 03:47 PM) *

How many browsers did you try it on? You should try it on several browsers, before thinking it's a browser problem. Below is a working example:[code]<?php



I don't think it's a browser problem anymore. I've tried on Opera, Chromium, and Firefox and they all act the same. Regardless of what php file I try to open in any of those browsers, the file is immediately downloaded and never displays. I think the problem is either in apache2.conf or phpadmin.conf but I don't know what to look for. I really don't want to purge the entire LAMP stack and do a total re-install.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 17 2020, 06:17 PM
Post #27


Programming Fanatic
********

Group: Members
Posts: 1,800
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Did you try my example code? Change the download folder and extension in the PHP code then save it in a new page, by itself. Be sure to use a .php extension when you save it. Now load the page in a browser. What happens?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Mar 17 2020, 06:58 PM
Post #28


.
********

Group: WDG Moderators
Posts: 8,632
Joined: 10-August 06
Member No.: 7



QUOTE(larry78723 @ Mar 17 2020, 10:32 PM) *

Regardless of what php file I try to open in any of those browsers, the file is immediately downloaded and never displays. I think the problem is either in apache2.conf or phpadmin.conf but I don't know what to look for. I really don't want to purge the entire LAMP stack and do a total re-install.

Maybe the server doesn't send the correct Mime type/Content-Type header ("text/html") along with the web page? But I assume LAMP includes the PHP module, and would then send the correct one.

Try testing it on your web host's server as well.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Mar 17 2020, 08:32 PM
Post #29


Computer says no.
********

Group: WDG Moderators
Posts: 19,246
Joined: 9-August 06
Member No.: 6



My thought also. Or the actual script changes the content-type?

Use some online tool to check what the content type is, for example this one: https://websniffer.cc/ .

Thing is, the content-type must be set to something the browser can't display (hence it offers to download it). If it wasn't set att all it would default to text/plain and the page would be displayed as text in the browser. At least in the best of worlds, that's what would happen.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Mar 17 2020, 08:47 PM
Post #30


Computer says no.
********

Group: WDG Moderators
Posts: 19,246
Joined: 9-August 06
Member No.: 6



Oh, you run this on your local machine? You can use Firefox.
Tools | Page Info
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
larry78723
post Mar 18 2020, 06:32 PM
Post #31


Member
***

Group: Members
Posts: 33
Joined: 5-March 20
Member No.: 27,220



Thanks everyone. Got it working on the host server.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

2 Pages V < 1 2
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 27th November 2020 - 11:52 PM