Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.