Jump to content

PHP File Download Prompt/Launch Failed!


akshay

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.