From 6f48c86265fea61c5138419f1d02e11294b10890 Mon Sep 17 00:00:00 2001 From: Luke Tainton Date: Sun, 9 Aug 2020 21:32:27 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20issue=20where=20files=20?= =?UTF-8?q?didn't=20upload=20on=20new=20request=20creation=20(#51)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luke Tainton --- app/public/actions/create.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/public/actions/create.php b/app/public/actions/create.php index a512743..7c8d339 100644 --- a/app/public/actions/create.php +++ b/app/public/actions/create.php @@ -16,29 +16,31 @@ $sql->execute(); } catch (PDOException $e) { // echo("Error:
" . $e->getMessage() . "
"); - $new_ticket_alert = array("danger", "Failed to save request: " . $e->getMessage()); + $alert = array("danger", "Failed to create request: " . $e->getMessage()); } // If file is uploaded, process that if(isset($_FILES['file']) && $_FILES['file']['name'] != "") { - try { + try { + $file_uuid = Uuid::uuid4()->toString(); $file_name = $_FILES['file']['name']; $file_size = $_FILES['file']['size']; $file_type = $_FILES['file']['type']; $file_tmp = $_FILES['file']['tmp_name']; - move_uploaded_file($file_tmp,"/srv/attachments/".$file_name); - $stmt = "INSERT INTO ticket_uploads (ticket, user, filename) VALUES (:ticket, :user, :name)"; + move_uploaded_file($file_tmp,$_ENV['ATTACHMENTS_PATH']."/".$file_uuid); + $stmt = "INSERT INTO ticket_uploads (id, ticket, user, filename) VALUES (:fileuuid, :ticket, :user, :name)"; $sql = $db->prepare($stmt); + $sql->bindParam(':fileuuid', $file_uuid); $sql->bindParam(':ticket', $tkt_uuid); $sql->bindParam(':user', $_SESSION['uuid']); $sql->bindParam(':name', $file_name); $sql->execute(); - } catch (PDOException $e) { - // echo("Error:
" . $e->getMessage() . "
"); - $new_ticket_alert = array("danger", "Failed to upload file: " . $e->getMessage()); - } + } catch (PDOException $e) { + $alert = array("danger", "Failed to upload file: " . $e->getMessage()); + } } - - header('Location: /view?rid=' . $tkt_uuid, true); + + $newURL = "/view?rid=" . $tkt_uuid; + echo(""); } ?>