From 14edd0a56705e2db046d05b2dd8e30b951897ad0 Mon Sep 17 00:00:00 2001 From: botanic Date: Mon, 8 Sep 2014 11:59:49 -0700 Subject: [PATCH] attachment error checking --- code/web/private_php/ams/autoload/ticket.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/code/web/private_php/ams/autoload/ticket.php b/code/web/private_php/ams/autoload/ticket.php index d70ba7036..a47a61659 100644 --- a/code/web/private_php/ams/autoload/ticket.php +++ b/code/web/private_php/ams/autoload/ticket.php @@ -620,15 +620,26 @@ class Ticket{ $ticket->load_With_TId($TId); //create the attachment! - $dbl = new DBLayer("lib"); - $dbl->insert("`ticket_attachments`", Array('ticket_TId' => $TId, 'Filename' => $filename, 'Filesize' => filesize($tempFile), 'Uploader' => $author, 'Path' => $randomString . "/" . $filename)); + try { + $dbl = new DBLayer("lib"); + $dbl->insert("`ticket_attachments`", Array('ticket_TId' => $TId, 'Filename' => $filename, 'Filesize' => filesize($tempFile), 'Uploader' => $author, 'Path' => $randomString . "/" . $filename)); + } + catch (Exception $e) { + return $false; + } + + mkdir($FILE_STORAGE_PATH . $randomString); - move_uploaded_file($tempFile,$targetFile); + $return = move_uploaded_file($tempFile,$targetFile); + + if ($return == false) { + $dbl->delete("`ticket_attachments`", array('Path' => $randomString . "/" . $filename), "`Path` = :Path"); + } //write a log entry Ticket_Log::createLogEntry( $TId, $author, 10); - return true; + return $return; } }