I have some problems. I have an mySQL database where i want to store some peronal files. I know it is not the best way to handle it but they are only some excel files so it shoeldnt be that big of a deal i thought. However i only download empty files or excel files with the PHP in it. THis is what is in my SQL table:
['name'] = The name of the file;
['mime'] = The type of file (application/vnd.ms-excel);
['size'] = The size of the data;
['data'] = And the data itself;
Also there is a user id for who can see the file.
This is what is in my download file:
if(isset($_GET['id']))
{
$id=intval($_GET['id']);
if($id <= 0)
{
die('Het opgegeven ID is niet correct');
}
else
{
$sql_facturen=mysqli_query($con,"SELECT mime, name, data FROM facturen WHERE id='" . $id . "'");
echo '<p> doing query </p>';
if($sql_facturen)
{
if(mysqli_num_rows($sql_facturen) == 1)
{
$row_facturen=mysqli_fetch_assoc($sql_facturen);
header("Content-Length: " . $row_facturen['size']);
header("Content-Type: " . $row_facturen['mime']);
header("Content-Disposition: attachment; filename=" .basename( $row_facturen['name']));
readfile($row_facturen['data']);
}
else
{
echo '<p>Geen factuur met dat id aanwezig</p>';
}
}
}
}
I have tried multiple header configurations that i found on the web. I also tried echo instead of readfile. However stil not the text that should be in it. Any sugestions? I am using google chrome.
EDIT: Here is my upload file:
if(isset($_FILES['uploaded_file']))
if($_FILES['uploaded_file']['error'] == 0)
{
$name = mysqli_real_escape_string($con, $_FILES['uploaded_file']['name']);
$mime = mysqli_real_escape_string($con, $_FILES['uploaded_file']['type']);
$data = mysqli_real_escape_string($con, ($_FILES['uploaded_file']['tmp_name']));
$size = mysqli_real_escape_string($con, $_FILES['uploaded_file']['size']);
$year = $_POST['year'];
$user_id = $_GET['id'];
$sql_upload=mysqli_query($con,"INSERT INTO facturen (name, mime, size, data, created, year, user_id) VALUES ('" . $name . "','" . $mime . "','" . $size . "','" . $data . "', NOW(), '" . $year . "','" . $user_id . "')");
if ($sql_upload)
{
echo 'Bestand is succesvol ingevoerd';
}
else
{
echo 'Error uploading';
echo mysqli_error($con);
}
}