akshay Posted June 16, 2010 Share Posted June 16, 2010 Hello. I used this code for launching a download... It doesn't seem to work fine. The download is launched but the file is always 26 bytes long and reads (if opened with text editor) "<h1>An error has occured</h1>". Please help Also Where can I get a LIST & Explanation of complete header() function. I mean what all I can do with header() (all commands) ? <?php /* include_once("../sql.php"); session_start(); $realsessid=session_id(); if (!isset($_GET['f']) || !isset($_GET['dlpath']) || !isset($_GET['sessid']) || !isset($_GET['dlpathtok'])) { header("location: http://mintload.com/dl/?f=".$_GET['f']); } else { if(($_GET['sessid'])!=$realsessid || $_GET['dlpathtok']!=md5($_GET['dlpath']) ) { header("location: http://mintload.com/dl/?f=".$_GET['f']); exit; } } $f=$_GET['f']; $dlpath=$_GET['dlpath']; //increment downloads by one...! $dinc="UPDATE files SET downloads=downloads+1 where fileid='$f' "; $dinc_res=mysql_query($dinc,$conn) or die(mysql_error()); */ //----------------------------------------------::: MAIN CODE BEGINS HERE::: //Launch dl: //$dlpath = file location if (file_exists($dlpath) && is_readable($dlpath)) { // get the file size and send the http headers $size = filesize($dlpath); $filename=basename($dlpath); header('Content-Type: application/octet-stream'); header('Content-Length: '.$size); header('Content-Disposition: attachment; filename='.$filename); header('Content-Transfer-Encoding: binary'); $file = @ fopen($dlpath, ‘rb’); if ($file) { // stream the file and exit the script when complete fpassthru($file); exit; } else { echo "<h2>An error occured!</h2>"; } } //file_exists ends else { echo "File does not exist!"; } ?> Link to comment https://forums.phpfreaks.com/topic/204929-php-file-download-promptlaunch-failed/ Share on other sites More sharing options...
kenrbnsn Posted June 16, 2010 Share Posted June 16, 2010 Why is most of your code commented out? Ken Link to comment https://forums.phpfreaks.com/topic/204929-php-file-download-promptlaunch-failed/#findComment-1072914 Share on other sites More sharing options...
Maq Posted June 16, 2010 Share Posted June 16, 2010 Also Where can I get a LIST & Explanation of complete header() function. I mean what all I can do with header() (all commands) ? Did you try the manual? http://us3.php.net/manual/en/function.header.php Link to comment https://forums.phpfreaks.com/topic/204929-php-file-download-promptlaunch-failed/#findComment-1073015 Share on other sites More sharing options...
ignace Posted June 16, 2010 Share Posted June 16, 2010 With header() you can send response headers. Link to comment https://forums.phpfreaks.com/topic/204929-php-file-download-promptlaunch-failed/#findComment-1073033 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.