Adding file upload
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 26 May 2017 12:35:39 +0000 (08:35 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 26 May 2017 12:35:56 +0000 (08:35 -0400)
Add file for upload and test that file added as attachment.

controllers/admin.php
views/supportForm.php

index a974273..0cd3cc0 100644 (file)
@@ -119,11 +119,26 @@ class SupportAdmin
                         'Time: ' . date('H:i:s ') . "\n" .
                         'User-Agent: ' . $_SERVER['HTTP_USER_AGENT'] . "\n" .
                         'Remote-Addr: ' . $_SERVER['REMOTE_ADDR'] . "\n";
+
+                    $attachment = '';
+                    if ( isset( $_FILES ) && is_array( $_FILES )
+                        && isset( $_FILES['file_upload'] ) && !$_FILES['file_upload']['error'] ) {
+                        // 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 '<pre>$_FILES: ' . print_r( $_FILES, true ) . '</pre>';
+                        if ( $fileUploaded ) {
+                            $attachment = $fileUploaded;
+                        }
+                    }
+
                     wp_mail(
                         GLM_SUPPORT_SUPPORT_EMAIL.','.$email.','.$values['email'],
                         GLM_SUPPORT_SUBJECT,
                         $msg,
-                        $hdrs
+                        $hdrs,
+                        $attachment
                     );
                 }
             }
index 85fff0a..5017e35 100644 (file)
@@ -59,7 +59,7 @@
                 margin: 1em 0;
             }
             table {
-                width: 600px;
+                width: 610px;
             }
             .req {
                 color: red;
@@ -74,7 +74,7 @@
                 <p>Please provide as much information as you can.</p>
             </div>
             <div>
-                <form action="<?php echo $supportFormActionUrl;?>" method="post">
+                <form action="<?php echo $supportFormActionUrl;?>" method="post" enctype="multipart/form-data">
                     <table>
                         <tr>
                             <td colspan="2"><b>Please help us provide the proper support</b></td>
                                 <textarea name="problem" required></textarea>
                             </td>
                         </tr>
+                        <tr>
+                            <td>
+                                <span class="req">*</span>&nbsp;Upload&nbsp;a&nbsp;screenshot: (jpg,gif,png)
+                            </td>
+                            <td>
+                                <input type="file" name="file_upload" />
+                            </td>
+                        </tr>
                         <tr>
                             <td></td>
                             <td>
                 </form>
             </div>
         </div><!-- #supportWrapper -->
-    </div>
\ No newline at end of file
+    </div>