|
Categorieën >
PHP
Bestand downloaden
SCornelis – 26/08/2010 00:33 (Laatst gewijzigd op 26/08/2010 01:36)
|
|
offline
|
Nieuw lid
|
Beste
Ik zit met het volgende probleem...
Ik heb een knop 'Download" op mijn webpagina. Het is de bedoeling, wanneer ik op die knop klik dat er een tekst verschijnt boven de knop EN dat er een document gedownload (bv. informatica.docx) wordt.
Ik heb het volgende geschreven ...
Kan iemand mij helpen, zodat het alsnog werkt.
De tekst wordt weergeven, maar de mogelijkheid om het bestand te downloaden komt niet tevoorschijn.
Alvast BEDANKT!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registratie</title>
<link href="stijl.css" rel="stylesheet" type="text/css" />
<style type="text/css">
input#btnDownload {border:1px solid #003366; font:Arial, Helvetica, sans-serif; font-size:8pt; background-color:#FFFFFF;}
</style>
</head>
<body>
<?php if (isset($_POST['btnControleer']))
{ echo ">> Downloaden << <br />"; } ?>
<form id="form1" name="frmDownload" method="post" action="">
<input name="btnDownload" type="submit" id="btnDownload" value="Download"/>
</form>
</body>
</html>
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Registratie</title> <link href="stijl.css" rel="stylesheet" type="text/css" /> <style type="text/css"> input#btnDownload {border:1px solid #003366; font:Arial, Helvetica, sans-serif; font-size:8pt; background-color:#FFFFFF;} </style> </head> <body> <?php if (isset($_POST['btnControleer'])) { echo ">> Downloaden << <br />"; } ?> <form id="form1" name="frmDownload" method="post" action=""> <input name="btnDownload" type="submit" id="btnDownload" value="Download"/> </form> </body> </html>
|
23 antwoorden
|
|
|
offline
|
Lid
|
Misschien ligt het aan de <br/ >, die moet namelijk zo: <br />
|
|
|
|
offline
|
Nieuw lid
|
@ FrankL
Bedankt voor je antwoord...
Dat is het probleem niet.
Zie maar, http://www.scornelis.be ... Wanneer je klikt op de knop, komt enkel de tekst en niet de vraag voor het document te downloaden.
|
|
|
|
offline
|
Nieuw lid
|
Ik zie ook nergens een bestand waar naar gelinkt wordt om te downloaden...
Greetz WeedSide
|
SCornelis – 26/08/2010 08:36 (Laatst gewijzigd op 26/08/2010 08:58)
|
|
offline
|
Nieuw lid
|
Ik heb een verwijzing opgegeven naar het document, maar nog steeds lukt het niet  ...
<?php include ("connectie.php");
$adres = "cornelis.sander@gmail.com"; ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registratie</title>
<link href="stijl.css" rel="stylesheet" type="text/css" />
<style type="text/css">
input#btnControleer {border:1px solid #003366; font:Arial, Helvetica, sans-serif; font-size:8pt; background-color:#FFFFFF;}
</style>
</head>
<body>
<?php if (isset($_POST['btnControleer']))
{ echo ">> Downloaden << <br />"; }
?>
<form id="form1" name="frmControle" method="post" action="http://www.scornelis.be/informatica.docx">
<input name="btnControleer" type="submit" id="btnControleer" value="Download"/>
</form>
</body>
</html>
<?php include ("connectie.php"); $adres = "cornelis.sander@gmail.com"; ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Registratie</title> <link href="stijl.css" rel="stylesheet" type="text/css" /> <style type="text/css"> input#btnControleer {border:1px solid #003366; font:Arial, Helvetica, sans-serif; font-size:8pt; background-color:#FFFFFF;} </style> </head> <body> <?php if (isset($_POST['btnControleer'])) { echo ">> Downloaden << <br />"; } ?> <form id="form1" name="frmControle" method="post" action="http://www.scornelis.be/informatica.docx"> <input name="btnControleer" type="submit" id="btnControleer" value="Download"/> </form> </body> </html>
|
FrankL – 26/08/2010 10:50 (Laatst gewijzigd op 26/08/2010 10:57)
|
|
offline
|
Lid
|
<?php include ("connectie.php");
$adres = "cornelis.sander@gmail.com"; ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registratie</title>
<link href="stijl.css" rel="stylesheet" type="text/css" />
<style type="text/css">
input#btnControleer {border:1px solid #003366; font:Arial, Helvetica, sans-serif; font-size:8pt; background-color:#FFFFFF;}
</style>
</head>
<body>
<?php
if (isset($_POST['btnControleer']))
{ echo "<a href='http://www.scornelis.be/informatica.docx'>>> Downloaden <<</a> <br />";
}
?>
<form id="form1" name="frmControle" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input name="btnControleer" type="submit" id="btnControleer" value="Download"/>
</form>
</body>
</html>
<?php include ("connectie.php"); $adres = "cornelis.sander@gmail.com"; ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Registratie</title> <link href="stijl.css" rel="stylesheet" type="text/css" /> <style type="text/css"> input#btnControleer {border:1px solid #003366; font:Arial, Helvetica, sans-serif; font-size:8pt; background-color:#FFFFFF;} </style> </head> <body> <?php if (isset($_POST['btnControleer'])) { echo "<a href='http://www.scornelis.be/informatica.docx'>>> Downloaden <<</a> <br />"; } ?> <form id="form1" name="frmControle" method="post" action=" <?php echo $_SERVER['PHP_SELF']; ?>"> <input name="btnControleer" type="submit" id="btnControleer" value="Download"/> </form> </body> </html>
Als je op de knop heb gedrukt ga je naar dezelfde pagina maar nu $_POST["btnControleer"] gezet, dus nu laat ie de link zien waar je kan downloaden, als je dan >> download << drukt doet ie het als het goed is.^^
Je zou ook met meerdere bestanden kunnen werken door bijvoorbeeld een hidden input te maken en daarin een get value ophalen welke dan de bestandsnaam is.
dus bijvoorbeeld
<?php include ("connectie.php");
$adres = "cornelis.sander@gmail.com"; ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registratie</title>
<link href="stijl.css" rel="stylesheet" type="text/css" />
<style type="text/css">
input#btnControleer {border:1px solid #003366; font:Arial, Helvetica, sans-serif; font-size:8pt; background-color:#FFFFFF;}
</style>
</head>
<body>
<?php
if (isset($_POST['btnControleer']))
{ echo "<a href='http://www.scornelis.be/".$_POST["bestand"]."'>>> Downloaden <<</a> <br />";
}
?>
<form id="form1" name="frmControle" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="bestand" value="<?php echo $_GET["naam"];?>"></input>
<input name="btnControleer" type="submit" id="btnControleer" value="Download"/>
</form>
</body>
</html>
<?php include ("connectie.php"); $adres = "cornelis.sander@gmail.com"; ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Registratie</title> <link href="stijl.css" rel="stylesheet" type="text/css" /> <style type="text/css"> input#btnControleer {border:1px solid #003366; font:Arial, Helvetica, sans-serif; font-size:8pt; background-color:#FFFFFF;} </style> </head> <body> <?php if (isset($_POST['btnControleer'])) { echo "<a href='http://www.scornelis.be/".$_POST["bestand"]."'>>> Downloaden <<</a> <br />"; } ?> <form id="form1" name="frmControle" method="post" action=" <?php echo $_SERVER['PHP_SELF']; ?>"> <input type="hidden" name="bestand" value=" <?php echo $_GET["naam"];? >"></input> <input name="btnControleer" type="submit" id="btnControleer" value="Download"/> </form> </body> </html>
Uiteraard moet dan op de pagina ervoor bijvoorbeeld zoiets zijn:
<a href="depagina.php?naam=bestand.extensie"></a>
Als het goed is werkt het zo in ieder geval.
EDIT: puntkomma vergeten achter $_GET["naam"]
|
|
|
|
offline
|
Nieuw lid
|
@ FrankL
Bedankt voor je antwoord ...
Het is goed, maar het zou eigenlijk bedoeling zijn dat ik niet op die link moet klikken, maar dat het automatisch (vraag om het bestand op te slaan) komt wanneer ik klik op de knop. De tekst ">> Download <<" moet uiteraard ook verschijnen.
Bedankt!
|
WeedSide – 26/08/2010 16:31 (Laatst gewijzigd op 26/08/2010 16:34)
|
|
offline
|
Nieuw lid
|
Aan je button toevoegen bij de input dus.
onclick="location.href=http://www.scornelis.be/'.$_POST["bestand"].'"
Zoiets durf niet te zeggen dat het gelijk werkt.
Ps expres geen code tags gebruikt, die veranderd de code.
Greetz WeedSide
|
SCornelis – 27/08/2010 00:30 (Laatst gewijzigd op 27/08/2010 09:31)
|
|
offline
|
Nieuw lid
|
@ WeedSide
Het scriptje werkt na de aanpassingen van jou nog niet  en ik weet eigenlijk niet wat verkeerd is  .
<?php include ("connectie.php");
$adres = "cornelis.sander@gmail.com"; ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registratie</title>
<link href="stijl.css" rel="stylesheet" type="text/css" />
<style type="text/css">
input#btnControleer {border:1px solid #003366; font:Arial, Helvetica, sans-serif; font-size:8pt; background-color:#FFFFFF;}
</style>
</head>
<body>
<?php
if (isset($_POST['btnControleer']))
{ echo ">> Downloaden <<"; } ?>
<form id="form1" name="frmControle" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input name="btnControleer" type="submit" id="btnControleer" value="Download" onclick="location.href=http://www.scornelis.be/'.$_POST["informatica.docx"].'"/>
</form>
</body>
</html>
<?php include ("connectie.php"); $adres = "cornelis.sander@gmail.com"; ?> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="stijl.css" rel="stylesheet" type="text/css" /> input#btnControleer {border:1px solid #003366; font:Arial, Helvetica, sans-serif; font-size:8pt; background-color:#FFFFFF;} <?php if (isset($_POST['btnControleer'])) { echo ">> Downloaden <<"; } ?> <form id="form1" name="frmControle" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input name="btnControleer" type="submit" id="btnControleer" value="Download" onclick="location.href=http://www.scornelis.be/'.$_POST["informatica.docx"].'"/>
|
|
|
|
offline
|
Lid
|
Je gaat nu een php variabele aanroepen zonder dat het in php staat zegmaar.
Dus:
onclick="location.href=http://www.scornelis.be/<?php echo $_POST["bestand"];?>"
als je met een index.php?naam=blabla werkt
of
onclick="location.href=http://www.scornelis.be/informatica.docx"
want $_POST["informatica.docx"] kan niet aangezien er geen input field is met de name informatica.docx
|
|
|
|
offline
|
Nieuw lid
|
Excuses met php ben ik inderdaad geen held 
onclick="location.href=http://www.scornelis.be/<?php echo $_POST["bestand"];?>"
Zou het moeten doen denk ik ja.
Greetz WeedSide
|
Dit onderwerp is gesloten.
|
|
|