mydog Posted August 18, 2006 Share Posted August 18, 2006 I've been trying to get this to work for some time actually.. And it doesn't want to work it seems. OH and I am very new to this site, and PHP. I know the basics of it though.[code]<head><title>Downloading $file</title><?php/*make sure you change all links to this page to download.php?file=none or it will try to find a file*/$id=$_GET['id']; //this will get the file in the urlswitch (id){case 0:$dl=minigame.exe;break;};{//redirect the page to the file in 1 secondecho '<meta http-equiv="refresh" content="1;url=$dl";>';//this will add 1 to the downloads$f=fopen('downloads.txt',"r");$num=fread($f,filesize('downloads.txt'));fclose($f);$num++;$f=fopen('downloads.txt',"w");fwrite($f,$num);fclose($f);}?></head>[/code]I have tried many variations and I put in the switch statement myself to see if it would work.. and it didn't. The problem here is that when it goes to get the file, it returns $dl in the address bar. When it should be the file. Thanks in adv. If I'm breaking any rules sorry I'm new ;) Quote Link to comment Share on other sites More sharing options...
Woolf Posted August 18, 2006 Share Posted August 18, 2006 Change this line: echo '<meta http-equiv="refresh" content="1;url=$dl";>';to: echo "<meta http-equiv=\"refresh\" content=\"1;url=$dl\";>";You need to know the difference between single quotes and double quotes. When echoing with single quotes ('), it will output the statement EXACTLY as shown. It will not fill in variables. However, when echoing with double quotes (") it will replace any variable (e.g. $dl) with the actual value. Note, however, that when echoing with double quotes, any double quote within the double quote must be forwarded with a slash, as you can see above. Quote Link to comment Share on other sites More sharing options...
mydog Posted August 18, 2006 Author Share Posted August 18, 2006 Wow..didn't know that thanks! ;D Quote Link to comment Share on other sites More sharing options...
Barand Posted August 18, 2006 Share Posted August 18, 2006 If it helps, this is how I handle downloads.1 ) create a file "download.php"[code]<?phpif (isset($_GET['file'])) { $fname = $_GET['file']; $path = 'c:/downloads/'; # path to download files on server - change as required # if (is_file($path.$fname)) { header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=$fname"); header("Content-length: " . filesize($path.$fname)); $fp = fopen($path.$fname, 'rb'); fpassthru($fp); }}?>[/code]In another page, list the download option for the user[code]<html><head><meta name="generator" content="PhpED Version 4.5 (Build 4513)"><title>Downloads</title></head><body><p>Select file to download </p><ul><li><a href='download.php?file=file1.zip'>File1.zip</a> <br>Description of file1</li><li><a href='download.php?file=file2.zip'>File2.zip</a> <br>Description of file2</li></ul></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.