di madownload yun galing sa database ko na pdf.. kapag pinidindot ko
ito code ko sa upload.php
<?php
include '../config/config.php';
?>
<?php
if(isset($_POST['submit'])){
$targetDir = "upload/";
$targetfile = $targetDir . basename($_FILES["pdfFile"]["name"]);
$filetype =strtolower(pathinfo($targetfile,PATHINFO_EXTENSION));
// check if file is a PDF and less than 20mb
if ($filetype == "pdf" && $_FILES['pdfFile']["size"] <= 5000000) {
if (move_uploaded_file($_FILES["pdfFile"]["tmp_name"], $targetfile)) {
echo "PDF file uploaded successfully.";
} else {
echo "Error uploading PDF file.";
}
} elseif ($filetype == "docx" && $_FILES["pdfFile"]["size"] <= 100000000) {
if (move_uploaded_file($_FILES["pdfFile"]["tmp_name"], $targetfile)) {
echo "Word file uploaded successfully.";
} else {
echo "Error uploading Word file.";
}
} else {
echo "Error: Invalid file type or size.";
}
$filename = $_FILES["pdfFile"]["name"];
$folder_path = $targetDir;
$time_stamp = date('Y-m-d H:i:s');
$stmt= $con ->prepare("INSERT INTO upload (filename,file_path, datetime) VALUES (?,?,?)");
$stmt->bind_param ("sss", $filename,$folder_path, $time_stamp);
if ($stmt->execute()){
echo "File Uploaded Successfully,";
}else{
echo "error";
}
$stmt->close();
$con->close();
}
?>
ito code ko naman sa form.php
<table class="tableload">
<tr class="trload">
<td class="tdload">
<ul>
<li><a href="download.php?id=<?php echo $fileupload; ?>">Download</a></li>
</ul>
</td>
</tr'>
</table>
<?php
ito code ko download.php
<?php
include '../config/config.php';
if (isset($_GET['id'])) {
$fileupload = $_GET['id'];
$stmt = $con->prepare("SELECT filename, file_path FROM upload WHERE id = ?");
$stmt->bind_param("i", $fileupload);
$stmt->execute();
$stmt->bind_result($filename, $file_path);
$stmt->fetch();
$stmt->close();
$fullFilePath = $file_path . $filename;
echo ($fullFilePath);
if (file_exists($fullFilePath)) {
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=\"" . $filename . "\"");
readfile($fullFilePath);
} else {
echo "File not found.";
}
}
// header('Location:form.php');
?>
ito code ko sa upload.php
<?php
include '../config/config.php';
?>
<?php
if(isset($_POST['submit'])){
$targetDir = "upload/";
$targetfile = $targetDir . basename($_FILES["pdfFile"]["name"]);
$filetype =strtolower(pathinfo($targetfile,PATHINFO_EXTENSION));
// check if file is a PDF and less than 20mb
if ($filetype == "pdf" && $_FILES['pdfFile']["size"] <= 5000000) {
if (move_uploaded_file($_FILES["pdfFile"]["tmp_name"], $targetfile)) {
echo "PDF file uploaded successfully.";
} else {
echo "Error uploading PDF file.";
}
} elseif ($filetype == "docx" && $_FILES["pdfFile"]["size"] <= 100000000) {
if (move_uploaded_file($_FILES["pdfFile"]["tmp_name"], $targetfile)) {
echo "Word file uploaded successfully.";
} else {
echo "Error uploading Word file.";
}
} else {
echo "Error: Invalid file type or size.";
}
$filename = $_FILES["pdfFile"]["name"];
$folder_path = $targetDir;
$time_stamp = date('Y-m-d H:i:s');
$stmt= $con ->prepare("INSERT INTO upload (filename,file_path, datetime) VALUES (?,?,?)");
$stmt->bind_param ("sss", $filename,$folder_path, $time_stamp);
if ($stmt->execute()){
echo "File Uploaded Successfully,";
}else{
echo "error";
}
$stmt->close();
$con->close();
}
?>
ito code ko naman sa form.php
<table class="tableload">
<tr class="trload">
<td class="tdload">
<ul>
<li><a href="download.php?id=<?php echo $fileupload; ?>">Download</a></li>
</ul>
</td>
</tr'>
</table>
<?php
ito code ko download.php
<?php
include '../config/config.php';
if (isset($_GET['id'])) {
$fileupload = $_GET['id'];
$stmt = $con->prepare("SELECT filename, file_path FROM upload WHERE id = ?");
$stmt->bind_param("i", $fileupload);
$stmt->execute();
$stmt->bind_result($filename, $file_path);
$stmt->fetch();
$stmt->close();
$fullFilePath = $file_path . $filename;
echo ($fullFilePath);
if (file_exists($fullFilePath)) {
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=\"" . $filename . "\"");
readfile($fullFilePath);
} else {
echo "File not found.";
}
}
// header('Location:form.php');
?>