Jump to content

having problems with my download script


yobo

Recommended Posts

hey all,

 

i am having some problems trying to download a file here is my hacks.php page

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

 

<body>

<table width="50%" border="0" cellspacing="0" cellpadding="3" align="left" >

<tr>

<th align="left">Hack Name</th>

<th align="left">Description</th>

<th align="left">Version</th>

<th align="left">Author</th>

<th align="left">Download</th>

</tr>

 

<?php

include("config.php");

 

// connect to the mysql server

$link = mysql_connect($server, $db_user, $db_pass)

or die ("Could not connect to mysql because ".mysql_error());

 

// select the database

mysql_select_db($database)

or die ("Could not select database because ".mysql_error());

echo  "<h1> $hackname  </h1>";

$search2=mysql_query("SELECT userid FROM users");

$search=mysql_query("SELECT * FROM hacks WHERE `hacksid`={$_GET['hacksid']}");

while($result=mysql_fetch_array($search)){

echo '<h1>';

echo $hackname = $result['hackname']  ;

echo '</h1>';

echo "<tr valign='top'>\n";

$hacksid = $result['hacksid'];

$hackname = $result['hackname'];

$description = $result['description'];

$version = $result['version'];

$username = $result['username'];

 

 

echo "<td>$hackname</td>\n";

echo "<td>$description</td>\n";

echo "<td>$version</td>\n";

echo "<td><a href='profile.php?userid=$username'>$username</a></td>\n";

echo "<td><a href='dload.php?hacksid=$hacksid'>Download</a></td>\n";

echo "</tr>\n";

}

 

?>

</body>

</html>

</table>

 

and here is my dload.php page

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

 

<body>

 

<?php

include("config.php");

 

// connect to the mysql server

$link = mysql_connect($server, $db_user, $db_pass)

or die ("Could not connect to mysql because ".mysql_error());

 

// select the database

mysql_select_db($database)

or die ("Could not select database because ".mysql_error());

 

if (isset($_GET['hacksid']))

 

 

$sql =mysql_query("SELECT * FROM hacks WHERE `hacksid`={$_GET['hacksid']}");

$result = @mysql_query($sql);

if (!result) {

exit('Database error: ' . mysql_error());

}

 

$file = mysql_fetch_array($result);

if (!$file) {

exit('file with given id not found in database!');

}

 

$filename = $file['hackname'];

$mimetype = $file['mimetype'];

$filedata = $file['filedata'];

$disposition = 'inline';

 

 

header("content-length: $filedata");

header("content-type: $mimetype");

header("content-disposition: $disposition; filename=$filename");

echo $filedata;

 

?>

</body>

</html>

 

 

basicly nothing happens no download box appears?

 

any help i would be appricated

Link to comment
https://forums.phpfreaks.com/topic/43134-having-problems-with-my-download-script/
Share on other sites

// Download file
$filename=$file['hackname'];
$mimetype = $file['mimetype'];
$filedata = $file['filedata'];
$disposition = 'inline';

header("Pragma: public");
header("Cache-Control: private");
header("Content-type: $mimetype");
header("Content-Disposition: $disposition; filename=$filename");
header("Content-length: $filedata");
readfile("$filename"); 

 

I have modified one of my download scripts and put your variables in, I know the script works so if yours does not it either does not get into that "if" statement or the data from the database isnt there

that is my modiffed code however it seems to download dload.php file and no files from the database

 

 

<?php header("Content-Disposition: attachment; filename=$hackname");

    header("Content-length: $filedata");

    header("Content-type: $mimetype");

?>

 

 

<?php

include("config.php");

 

// connect to the mysql server

$link = mysql_connect($server, $db_user, $db_pass)

or die ("Could not connect to mysql because ".mysql_error());

 

// select the database

mysql_select_db($database)

or die ("Could not select database because ".mysql_error());

 

if(isset($_GET['hacksid']))

{

    $hacksid      = $_GET['hacksid'];

    $query  = "SELECT *FROM hacks WHERE hacksid = '$hacksid'";

    $result  = mysql_query($query) or die('Error, query failed'.mysql_error());

    list($hackname, $mimetype, $filedata) = mysql_fetch_array($result);

 

   

   

 

    exit;

}

 

?>

 

 

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.