-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf_handler.php
executable file
·40 lines (38 loc) · 1.22 KB
/
pdf_handler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
session_start();
ini_set('display_errors', 1);
require_once("Dao.php");
// save a product, including name, description, and an image path
// if(isset($_POST["pdfSubmitButton"])){
// $songname = $_POST['pdfname'];
// $description = $_POST['pdfdescription'];
// $author = $_SESSION['username'];
// }else{
// header("Location:myaccount.php");exit;
// }
$songname = (isset($_POST["pdfname"])) ? $_POST["pdfname"] : "";
$description = (isset($_POST["pdfdescription"])) ? $_POST["pdfdescription"] : "";
$author = $_SESSION['username'];
$imagePath = "";
if (count($_FILES) > 0) {
if ($_FILES["pdffile"]["error"] > 0) {
throw new Exception("Error: " . $_FILES["pdffile"]["error"]);
} else {
$basePath = "/app/";
// echo print_r($_FILES, 1);
// exit;
$imagePath = "/pdfcontent/" . $_FILES["pdffile"]["name"];
if (!move_uploaded_file($_FILES["pdffile"]["tmp_name"], $basePath . $imagePath)) {
throw new Exception("File move failed");
}
}
}
try{
$dao = new Dao();
$dao->savePdf($songname, $description, $imagePath, $author);
} catch (Exception $e){
var_dump($e);
die;
}
header("Location:learn.php");
exit;