Hi ppl,
When i am downloading a file from my uploads folder it always downloads a file named download.htm even though in the folder there is a txt file.
Anyone knows whats the problem?
My upload.php
My Download.php
My view.php (where the download link is)
Thaks in advance.
Peace and Love,
Slaxer13
When i am downloading a file from my uploads folder it always downloads a file named download.htm even though in the folder there is a txt file.
Anyone knows whats the problem?
My upload.php
Code:
<?php
include_once 'dbconfig.php';
if(isset($_POST['btn-upload']))
{
$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="uploads/";
// new file size in KB
$new_size = $file_size/1024;
// new file size in KB
// make file name in lower case
$new_file_name = strtolower($file);
// make file name in lower case
$final_file=str_replace(' ','-',$new_file_name);
if(move_uploaded_file($file_loc,$folder.$final_file))
{
$sql="INSERT INTO tbl_uploads(file,type,size) VALUES('$final_file','$file_type','$new_size')";
mysql_query($sql);
?>
<script>
alert('successfully uploaded');
window.location.href='view.php?success';
</script>
<?php
}
else
{
?>
<script>
alert('error while uploading file');
window.location.href='upload.php?fail';
</script>
<?php
}
}
?>
Code:
<?php
require 'dbconfig.php';
$query = "SELECT * FROM tbl_uploads";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result)==0){
echo "Database is empty <br>";
}
else{
while(list($id, $name) = mysql_fetch_array($result)){
echo "<a href=\"download.php?id=\$id\">$name</a><br>";
}
}
if(isset($_GET['id'])){
$id = $_GET['id'];
$query = "SELECT file, type, size FROM tbl_uploads WHERE id = '$id'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_row($result);
header("Content-Disposition: attachment; filename=$name");
header("Content-type: $type");
header("Content-length: $size");
print $content;
}
?>
Code:
<?php
include_once 'dbconfig.php';
if(isset($_GET['remove_id']))
{
$res=mysql_query("SELECT file FROM tbl_uploads WHERE id=".$_GET['remove_id']);
$row=mysql_fetch_array($res);
mysql_query("DELETE FROM tbl_uploads WHERE id=".$_GET['remove_id']);
unlink("uploads/".$row['file']);
header("Location: view.php");
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Delete Uploaded Files From Folder in PHP</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript">
function remove(id)
{
if(confirm(' Sure to remove file ? '))
{
window.location='delete.php?remove_id='+id;
}
}
</script>
</head>
<body>
<div id="header">
<label>Delete Uploaded Files From Folder in PHP</label>
</div>
<div id="body">
<table width="80%" border="1">
<tr>
<th colspan="4">your uploads...<label><a href="relatorios.php">upload new files...</a></label></th>
</tr>
<tr>
<td>File Name</td>
<td>File Type</td>
<td>File Size(KB)</td>
<td>View</td>
<td>Delete</td>
<td>Download</td>
<?php
$sql="SELECT * FROM tbl_uploads";
$result_set=mysql_query($sql);
while($row=mysql_fetch_array($result_set))
{
?>
</tr>
<tr>
<td><?php echo $row['file'] ?></td>
<td><?php echo $row['type'] ?></td>
<td><?php echo $row['size'] ?></td>
<td><a href="uploads/<?php echo $row['file'] ?>" target="_blank">view file</a></td>
<td><a href="javascript:remove(<?php echo $row['id'] ?>)">Delete file</a></td>
<td><a href="download.php">Download</a></td>
</tr>
<?php
}
?>
</table>
</div>
</body>
</html>
Peace and Love,
Slaxer13
Comment