From: Steve Sutton Date: Fri, 26 May 2017 16:47:54 +0000 (-0400) Subject: Setup file size max for the upload. X-Git-Tag: v1.0.0^2~1^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=3731f5054a6809f8c9be48290335af3f959a5bbf;p=WP-Plugins%2Fglm-support-form.git Setup file size max for the upload. Also setting up javascript which will check the file size to make sure it no larger than 1MB. File is uploaded to uploads/glm-support and remove from the server when the file get's sent in the email as an attachment. --- diff --git a/controllers/admin.php b/controllers/admin.php index 0cd3cc0..27a894c 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -123,13 +123,19 @@ class SupportAdmin $attachment = ''; if ( isset( $_FILES ) && is_array( $_FILES ) && isset( $_FILES['file_upload'] ) && !$_FILES['file_upload']['error'] ) { + // Create a directory in uploads for support files if needed + $upPath = wp_upload_dir(); + $filePath = $upPath['basedir'] . '/glm-support'; + if ( !is_dir( $filePath ) ) { + $oldumask = umask( 0 ); + mkdir( $filePath, 0770 ); + umask( $oldumask ); + } // move the uploaded file - $upload_path = wp_upload_dir(); - $file_name = $upload_path['basedir'] . '/' . $_FILES['file_upload']['name']; - $fileUploaded = move_uploaded_file( $_FILES['file_upload']['tmp_name'], $file_name ); - echo '
$_FILES: ' . print_r( $_FILES, true ) . '
'; - if ( $fileUploaded ) { - $attachment = $fileUploaded; + $fileName = wp_unique_filename( $filePath, $_FILES['file_upload']['name'] ); + $fileUploaded = move_uploaded_file( $_FILES['file_upload']['tmp_name'], $fileName ); + if ( $fileUploaded && $fileName ) { + $attachment = $fileName; } } @@ -140,6 +146,12 @@ class SupportAdmin $hdrs, $attachment ); + + + // If there's a file attachment then delete file from server + if ( isset( $fileName ) && $fileName && is_file( $filePath . '/' . $fileName ) ) { + unlink( $filePath . '/' . $fileName ); + } } } } diff --git a/views/supportForm.php b/views/supportForm.php index 5017e35..a3c22ad 100644 --- a/views/supportForm.php +++ b/views/supportForm.php @@ -72,9 +72,11 @@

Use this support form to quickly report an issue with your web site.

Please provide as much information as you can.

+

If you have a screenshot to upload the file must be no larger than 1MB.

+ @@ -129,10 +131,11 @@ @@ -144,6 +147,24 @@
Please help us provide the proper support
- * Upload a screenshot: (jpg,gif,png) + * Upload a screenshot: + (1MB Max) - +

* denotes required field

+
+