temprarely download problem (download.php)

Post here is you are having problems with any of the tutorials.
Post Reply
rizwan
Posts: 3
Joined: Fri Nov 25, 2011 6:15 pm

temprarely download problem (download.php)

Post by rizwan »

all files are doing properly work but i have problem in this file
download.php
this the code
<?php
include('core/init.inc.php');
if (isset($_GET['file_id'])) {
$file_id = (int)$_GET['file_id'];
$file = mysql_query("SELECT `file_name`, `file_expiry` FROM `files` WHERE `file_id` = {$file_id}");
if (mysql_num_rows($file) != 1) {
echo 'file ID is invalid';
}
else {
$row = mysql_fetch_assoc($file);
if ($row['file_expiry'] < time()){
echo "this file hase been expired.";
}
else{
$path = "core/file/{$row['file_name']}";
header('content-Type: application/octetstream');
header('Content-Type: application/octet-stream');
header('Content-Description: File Transfer');
header("Content-Description: attachment; filename=\{$row['file_name']}"\==);
header('Content-Length: ' . filesize($path));
readfile($path);
}
}
}
?>
<html>
<head>
<title>better php blog tutorials</title>
</head>
<body>
</body>
</html>



error sam llike this
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Documents and Settings\Administrator\Desktop\VertrigoServ\www\temprarely download\download.php on line 19
this is my files
file_list.php
<?php
include('core/init.inc.php');
$files = mysql_query('SELECT `file_name`, `file_expiry`, `file_id` FROM `files`');
?>
<html>
<head>
<title>better php blog tutorials</title>
</head>
<body>
<div>
<table border="4">
<tr>
<th>File Name</th>
<th>Expires</th>
</tr>
<?php
while (($row = mysql_fetch_assoc($files)) !== false) {
?>
<tr>
<td><a href="download.php?file_id=<?php echo $row['file_id']; ?>"><?php echo $row['file_name']; ?></a></td>
<td><?php echo date('d/m/y H:s:i', $row['file_expiry']); ?>
</td>
</tr>
<?php
}
?>
</table>
</div>
</body>
</html>


(upload.php) file
<?php
include('core/init.inc.php');
if (isset($_POST['expiry'], $_FILES['file'])){
$file_name = mysql_real_escape_string($_FILES['file']['name']);
$expiry = time() + ((int)$_POST['expiry'] * 60);
mysql_query("INSERT INTO `files` (`file_name`, `file_expiry`) VALUES ('{$file_name}', {$expiry})");
move_uploaded_file($_FILES['file']['tmp_name'], "core/files/{$_FILES['file']['name']}");
}
?>
<html>
<head>
<title>better php blog tutorials</title>
</head>
<body>
<div>
<form action="" method="post" enctype="multipart/form-data">
<input type="text" name="expiry">
<p/>
<input type="file" name="file">
</p>
<input type="submit" value="submit">
</p>
</form>
</div>
</body>
</html>


in core folder (init.inc.php) file and one folder folder name is (files)
i have a database (downloads)
init.inc.php
<?php
mysql_connect('127.0.0.1','root','vertrigo');
mysql_select_db('downloads');
?>
<html>
<head>
<title>better php blog tutorials</title>
</head>
<body>
<div>

</div>
</body>
</html>
Last edited by rizwan on Thu Dec 08, 2011 11:19 am, edited 1 time in total.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: temprarely download problem (download.php)

Post by jacek »

What does your init.inc.php file look like ? The errors is because you have some output from the script before you use the header() function.
Image
Post Reply