PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Ruski
Forum Commoner
Posts: 28 Joined: Thu May 26, 2005 3:45 am
Post
by Ruski » Sun Jun 19, 2005 5:32 am
Im using a fgets function to download a specified file from my website, but instead of downloading it, it echos it below the button i press to download.
Site:
http://www.rscheetah.com/download.php
(click on Cheetah1.0 and see for yourself)
Here is the php script that i made:
Code: Select all
<FORM method="post" action="downloads.php?file=p1.gif" name="form1">
<input type="submit" name="Submit" value="Cheetah 1.0">
</FORM>
<?php
if($file != "")
{
$fp = fopen('./downloads/'.$file, 'r');
set_time_limit(0);
while(!feof($fp))
{
fgets($fp, 10240);
}
fclose($fp);
}
?>
Thanks in advance
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Sun Jun 19, 2005 6:44 am
That is because you output the file after your "<form>" stuff.... The code does exactly what you tell it to do...
Do you want two different files?
blah.html
Code: Select all
<form action="e;downloads.php"e; method="e;post"e;>
<input type="e;hidden"e; name="e;file"e; value="e;blah.gif"e;/>
<input type="e;submit"e;/>
</form>
downloads.php
Code: Select all
<?php
if (isset($_POST['file']))
{
set_time_limit(0);
echo file_get_contents('./downloads/' . $_POST['file']);
}
?>
Ruski
Forum Commoner
Posts: 28 Joined: Thu May 26, 2005 3:45 am
Post
by Ruski » Sun Jun 19, 2005 7:21 am
I dont want it to echo the file's content, i want it to download the file onto the user's computer, such as pop up a download box, that says open or save...
Thanks for your help
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Sun Jun 19, 2005 7:49 am
If you don't want that to happen.. You shoudn't write code that does exactly what you DO NOT want.
I gave you an example of you could change the code to something that does what you do want...
You can find another sample of some code that offers a file for download
http://timvw.madoka.be/programming/php/download.txt