$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 '<pre>$_FILES: ' . print_r( $_FILES, true ) . '</pre>';
- 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;
}
}
$hdrs,
$attachment
);
+
+
+ // If there's a file attachment then delete file from server
+ if ( isset( $fileName ) && $fileName && is_file( $filePath . '/' . $fileName ) ) {
+ unlink( $filePath . '/' . $fileName );
+ }
}
}
}
<div id="supportIntro">
<p>Use this support form to quickly report an issue with your web site.</p>
<p>Please provide as much information as you can.</p>
+ <p>If you have a screenshot to upload the file must be no larger than 1MB.</p>
</div>
<div>
<form action="<?php echo $supportFormActionUrl;?>" method="post" enctype="multipart/form-data">
+ <input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
<table>
<tr>
<td colspan="2"><b>Please help us provide the proper support</b></td>
</tr>
<tr>
<td>
- <span class="req">*</span> Upload a screenshot: (jpg,gif,png)
+ <span class="req">*</span> Upload a screenshot:
+ (1MB Max)
</td>
<td>
- <input type="file" name="file_upload" />
+ <input id="myfile" type="file" name="file_upload" />
</td>
</tr>
<tr>
</table>
<p><span style="color:red">*</span> denotes required field</p>
</form>
+
</div>
</div><!-- #supportWrapper -->
</div>
+<script>
+function init() {
+ var myfiles = document.getElementById( 'myfile' );
+ myfiles.addEventListener('change', process);
+}
+function process(event) {
+ var files = event.target.files;
+ var myfile = files[0];
+ if ( myfile.size > 1048576 ) {
+ alert( 'Your file is too large!\nPlease try another file.' );
+ var myfiles = document.getElementById( 'myfile' );
+ myfiles.value = '';
+ }
+ console.log( myfile );
+}
+window.addEventListener('load', init);
+</script>