Version Description
- Added maximum upload size limit setting.
- Stronger security: uploads now go through admin-ajax and check_admin_referer is called before any chunks are touched.
Download this release
Release Info
Developer | andtrev |
Plugin | Tuxedo Big File Uploads |
Version | 1.2 |
Comparing to | |
See all releases |
Code changes from version 1.1 to 1.2
- readme.txt +16 -11
- tux_handle_upload.php +0 -106
- tuxedo_big_file_uploads.php +241 -3
- uninstall.php +1 -0
readme.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
=== Tuxedo Big File Uploads ===
|
2 |
Contributors: andtrev
|
3 |
-
Tags: AJAX, file uploader, files, files uploader, ftp, image uploader, plugin, upload
|
4 |
Requires at least: 3.4
|
5 |
-
Tested up to: 4.
|
6 |
-
Stable tag: 1.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -11,42 +11,47 @@ Enables large file uploads in the built-in WordPress media uploader.
|
|
11 |
|
12 |
== Description ==
|
13 |
|
14 |
-
|
15 |
|
16 |
-
No messing with initialization files or settings. No need to FTP.
|
17 |
|
18 |
Simply activate the plugin and use the media uploader as you normally would.
|
19 |
|
20 |
The browser uploader option is not supported, the multi-file uploader must be used to enable large file uploads.
|
21 |
|
22 |
* Small footprint that doesn't bog down WordPress with unnecessary features.
|
23 |
-
* Shows available disk space for temporary uploads directory as maximum upload file size in media uploader.
|
24 |
-
* Options for chunk size and max retries are available under the Uploading Files section on the Settings -> Media page.
|
25 |
|
26 |
In essence the plugin changes the Plupload settings for uploads and points the AJAX url to the plugin. This processes the
|
27 |
-
upload in chunks (separate smaller pieces) before handing it off to
|
28 |
|
29 |
== Installation ==
|
30 |
|
31 |
1. Upload the plugin files to the `/wp-content/plugins/tuxedo-big-file-uploads` directory, or install the plugin through the WordPress plugins screen directly.
|
32 |
2. Activate the plugin through the 'Plugins' screen in WordPress.
|
33 |
-
3. Use the Settings -> Media screen to configure the plugin.
|
34 |
|
35 |
== Frequently Asked Questions ==
|
36 |
|
37 |
= How big can uploads be? =
|
38 |
|
39 |
-
Uploads can be as large as available disk space for temporary files allows
|
|
|
40 |
|
41 |
= Why does the maximum file size decrease after an upload? =
|
42 |
|
43 |
-
|
44 |
Free disk space will decrease as files are uploaded.
|
45 |
Additionally some systems use a separate partition for temporary files, free space may fluctuate as files
|
46 |
are uploaded and moved out of the temporary folder.
|
47 |
|
48 |
== Changelog ==
|
49 |
|
|
|
|
|
|
|
|
|
50 |
= 1.1 =
|
51 |
* Security fix: non-authenticated user could upload.
|
52 |
|
1 |
=== Tuxedo Big File Uploads ===
|
2 |
Contributors: andtrev
|
3 |
+
Tags: AJAX, file uploader, files, files uploader, ftp, image uploader, plugin, upload, increase file upload limit
|
4 |
Requires at least: 3.4
|
5 |
+
Tested up to: 4.9.5
|
6 |
+
Stable tag: 1.2
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
11 |
|
12 |
== Description ==
|
13 |
|
14 |
+
Increase file upload limit in the standard built-in WordPress media uploader. Uploads can be as large as available disk space allows.
|
15 |
|
16 |
+
No messing with Apache/PHP initialization files or settings. No need to FTP.
|
17 |
|
18 |
Simply activate the plugin and use the media uploader as you normally would.
|
19 |
|
20 |
The browser uploader option is not supported, the multi-file uploader must be used to enable large file uploads.
|
21 |
|
22 |
* Small footprint that doesn't bog down WordPress with unnecessary features.
|
23 |
+
* Shows available disk space for temporary uploads directory or maximum upload size limit setting as maximum upload file size in media uploader.
|
24 |
+
* Options for maximum upload size limit, chunk size and max retries are available under the Uploading Files section on the Settings -> Media page.
|
25 |
|
26 |
In essence the plugin changes the Plupload settings for uploads and points the AJAX url to the plugin. This processes the
|
27 |
+
upload in chunks (separate smaller pieces) before handing it off to WordPress.
|
28 |
|
29 |
== Installation ==
|
30 |
|
31 |
1. Upload the plugin files to the `/wp-content/plugins/tuxedo-big-file-uploads` directory, or install the plugin through the WordPress plugins screen directly.
|
32 |
2. Activate the plugin through the 'Plugins' screen in WordPress.
|
33 |
+
3. Use the Settings -> Media -> Uploading Files screen to configure the plugin.
|
34 |
|
35 |
== Frequently Asked Questions ==
|
36 |
|
37 |
= How big can uploads be? =
|
38 |
|
39 |
+
Uploads can be as large as available disk space for temporary files allows, or up to the maximum upload size
|
40 |
+
limit set in Settings -> Media -> Uploading Files.
|
41 |
|
42 |
= Why does the maximum file size decrease after an upload? =
|
43 |
|
44 |
+
If no maximum upload size limit is set, then maximum file size is listed as the available free disk space for temporary uploads.
|
45 |
Free disk space will decrease as files are uploaded.
|
46 |
Additionally some systems use a separate partition for temporary files, free space may fluctuate as files
|
47 |
are uploaded and moved out of the temporary folder.
|
48 |
|
49 |
== Changelog ==
|
50 |
|
51 |
+
= 1.2 =
|
52 |
+
* Added maximum upload size limit setting.
|
53 |
+
* Stronger security: uploads now go through admin-ajax and check_admin_referer is called before any chunks are touched.
|
54 |
+
|
55 |
= 1.1 =
|
56 |
* Security fix: non-authenticated user could upload.
|
57 |
|
tux_handle_upload.php
DELETED
@@ -1,106 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* TuxedoBigFileUploads Handle Upload
|
4 |
-
*
|
5 |
-
* Ajax callback for plupload to handle chunked uploads.
|
6 |
-
*
|
7 |
-
* @package TuxedoBigFileUploads
|
8 |
-
* @since 1.0.0
|
9 |
-
*
|
10 |
-
* Based on code by Davit Barbakadze
|
11 |
-
* https://gist.github.com/jayarjo/5846636
|
12 |
-
*/
|
13 |
-
|
14 |
-
/** Check that we have an upload and there are no errors. */
|
15 |
-
if ( empty( $_FILES ) || $_FILES['async-upload']['error'] ) {
|
16 |
-
/** Failed to move uploaded file. */
|
17 |
-
die();
|
18 |
-
}
|
19 |
-
|
20 |
-
/** Authenticate user. */
|
21 |
-
require_once( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/wp-load.php' );
|
22 |
-
|
23 |
-
if ( ! is_user_logged_in() || ! current_user_can( 'upload_files' ) ) {
|
24 |
-
die();
|
25 |
-
}
|
26 |
-
|
27 |
-
if ( ! function_exists( 'mime_content_type' ) ) {
|
28 |
-
/**
|
29 |
-
* Return a file's mime type.
|
30 |
-
*
|
31 |
-
* @since 1.0.0
|
32 |
-
*
|
33 |
-
* @param string $filename File name.
|
34 |
-
* @return var string $mimetype Mime type.
|
35 |
-
*/
|
36 |
-
function mime_content_type( $filename ) {
|
37 |
-
|
38 |
-
if ( function_exists( 'finfo_open' ) ) {
|
39 |
-
$finfo = finfo_open( FILEINFO_MIME );
|
40 |
-
$mimetype = finfo_file( $finfo, $filename );
|
41 |
-
finfo_close( $finfo );
|
42 |
-
return $mimetype;
|
43 |
-
} else {
|
44 |
-
ob_start();
|
45 |
-
system( 'file -i -b ' . $filename );
|
46 |
-
$output = ob_get_clean();
|
47 |
-
$output = explode( '; ', $output );
|
48 |
-
if ( is_array( $output ) ) {
|
49 |
-
$output = $output[0];
|
50 |
-
}
|
51 |
-
return $output;
|
52 |
-
}
|
53 |
-
|
54 |
-
}
|
55 |
-
}
|
56 |
-
|
57 |
-
/** Check and get file chunks. */
|
58 |
-
$chunk = isset( $_REQUEST['chunk']) ? intval( $_REQUEST['chunk'] ) : 0;
|
59 |
-
$chunks = isset( $_REQUEST['chunks']) ? intval( $_REQUEST['chunks'] ) : 0;
|
60 |
-
|
61 |
-
/** Get file name and path + name. */
|
62 |
-
$fileName = isset( $_REQUEST['name'] ) ? $_REQUEST['name'] : $_FILES['async-upload']['name'];
|
63 |
-
$filePath = dirname( $_FILES['async-upload']['tmp_name'] ) . '/' . md5( $fileName );
|
64 |
-
|
65 |
-
/** Open temp file. */
|
66 |
-
$out = @fopen( "{$filePath}.part", $chunk == 0 ? 'wb' : 'ab' );
|
67 |
-
if ( $out ) {
|
68 |
-
|
69 |
-
/** Read binary input stream and append it to temp file. */
|
70 |
-
$in = @fopen( $_FILES['async-upload']['tmp_name'], 'rb' );
|
71 |
-
|
72 |
-
if ( $in ) {
|
73 |
-
while ( $buff = fread( $in, 4096 ) ) {
|
74 |
-
fwrite( $out, $buff );
|
75 |
-
}
|
76 |
-
} else {
|
77 |
-
/** Failed to open input stream. */
|
78 |
-
/** Attempt to clean up unfinished output. */
|
79 |
-
@fclose( $out );
|
80 |
-
@unlink( "{$filePath}.part" );
|
81 |
-
die();
|
82 |
-
}
|
83 |
-
|
84 |
-
@fclose( $in );
|
85 |
-
@fclose( $out );
|
86 |
-
|
87 |
-
@unlink( $_FILES['async-upload']['tmp_name'] );
|
88 |
-
|
89 |
-
} else {
|
90 |
-
/** Failed to open output stream. */
|
91 |
-
die();
|
92 |
-
}
|
93 |
-
|
94 |
-
/** Check if file has finished uploading all parts. */
|
95 |
-
if ( ! $chunks || $chunk == $chunks - 1 ) {
|
96 |
-
|
97 |
-
/** Recreate upload in $_FILES global and pass off to WordPress. */
|
98 |
-
rename( "{$filePath}.part", $_FILES['async-upload']['tmp_name'] );
|
99 |
-
$_FILES['async-upload']['name'] = $fileName;
|
100 |
-
$_FILES['async-upload']['size'] = filesize( $_FILES['async-upload']['tmp_name'] );
|
101 |
-
$_FILES['async-upload']['type'] = mime_content_type( $_FILES['async-upload']['tmp_name'] );
|
102 |
-
/** Set $_SERVER'[PHP_SELF'] global to wp-admin upload AJAX to stop a PHP notice from /wp-includes/vars.php line 31. */
|
103 |
-
$_SERVER['PHP_SELF'] = '/wp-admin/async-upload.php';
|
104 |
-
require_once( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/wp-admin/async-upload.php' );
|
105 |
-
|
106 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tuxedo_big_file_uploads.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Tuxedo Big File Uploads
|
4 |
* Plugin URI: https://github.com/andtrev/Tuxedo-Big-File-Uploads
|
5 |
* Description: Enables large file uploads in the built-in WordPress media uploader.
|
6 |
-
* Version: 1.
|
7 |
* Author: Trevor Anderson
|
8 |
* Author URI: https://github.com/andtrev
|
9 |
* License: GPLv2 or later
|
@@ -25,7 +25,7 @@
|
|
25 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
*
|
27 |
* @package TuxedoBigFileUploads
|
28 |
-
* @version 1.0
|
29 |
*/
|
30 |
|
31 |
/**
|
@@ -80,9 +80,24 @@ class TuxedoBigFileUploads {
|
|
80 |
|
81 |
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
|
82 |
add_filter( 'plupload_init', array( $this, 'filter_plupload_settings' ) );
|
|
|
83 |
add_filter( 'plupload_default_settings', array( $this, 'filter_plupload_settings' ) );
|
|
|
84 |
add_filter( 'upload_size_limit', array( $this, 'filter_upload_size_limit' ) );
|
85 |
add_action( 'admin_init', array( $this, 'settings_api_init' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
}
|
88 |
|
@@ -101,7 +116,7 @@ class TuxedoBigFileUploads {
|
|
101 |
if ( $tuxbfu_max_retries < 1 ) {
|
102 |
$tuxbfu_max_retries = 5;
|
103 |
}
|
104 |
-
$plupload_settings['url'] =
|
105 |
$plupload_settings['filters']['max_file_size'] = $this->filter_upload_size_limit('') . 'b';
|
106 |
$plupload_settings['chunk_size'] = $tuxbfu_chunk_size . 'kb';
|
107 |
$plupload_settings['max_retries'] = $tuxbfu_max_retries;
|
@@ -134,6 +149,15 @@ class TuxedoBigFileUploads {
|
|
134 |
*/
|
135 |
public function filter_upload_size_limit( $unused ) {
|
136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
$bytes = disk_free_space( sys_get_temp_dir() );
|
138 |
if ( $bytes === false ) {
|
139 |
$bytes = 0;
|
@@ -151,6 +175,13 @@ class TuxedoBigFileUploads {
|
|
151 |
*/
|
152 |
public function settings_api_init() {
|
153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
add_settings_field(
|
155 |
'tuxbfu_chunk_size',
|
156 |
__( 'Chunk Size (kb)', 'tuxedo-big-file-uploads' ),
|
@@ -165,11 +196,28 @@ class TuxedoBigFileUploads {
|
|
165 |
'media',
|
166 |
'uploads'
|
167 |
);
|
|
|
168 |
register_setting( 'media', 'tuxbfu_chunk_size', 'intval' );
|
169 |
register_setting( 'media', 'tuxbfu_max_retries', 'intval' );
|
170 |
|
171 |
}
|
172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
/**
|
174 |
* Output chunk size input control.
|
175 |
*
|
@@ -202,6 +250,196 @@ class TuxedoBigFileUploads {
|
|
202 |
|
203 |
}
|
204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
}
|
206 |
|
207 |
/** Instantiate the plugin class. */
|
3 |
* Plugin Name: Tuxedo Big File Uploads
|
4 |
* Plugin URI: https://github.com/andtrev/Tuxedo-Big-File-Uploads
|
5 |
* Description: Enables large file uploads in the built-in WordPress media uploader.
|
6 |
+
* Version: 1.2
|
7 |
* Author: Trevor Anderson
|
8 |
* Author URI: https://github.com/andtrev
|
9 |
* License: GPLv2 or later
|
25 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
*
|
27 |
* @package TuxedoBigFileUploads
|
28 |
+
* @version 1.2.0
|
29 |
*/
|
30 |
|
31 |
/**
|
80 |
|
81 |
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
|
82 |
add_filter( 'plupload_init', array( $this, 'filter_plupload_settings' ) );
|
83 |
+
add_filter( 'upload_post_params', array( $this, 'filter_plupload_params' ) );
|
84 |
add_filter( 'plupload_default_settings', array( $this, 'filter_plupload_settings' ) );
|
85 |
+
add_filter( 'plupload_default_params', array( $this, 'filter_plupload_params' ) );
|
86 |
add_filter( 'upload_size_limit', array( $this, 'filter_upload_size_limit' ) );
|
87 |
add_action( 'admin_init', array( $this, 'settings_api_init' ) );
|
88 |
+
add_action( 'wp_ajax_tux_big_file_uploads', array( $this, 'ajax_chunk_receiver' ) );
|
89 |
+
|
90 |
+
}
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Filter plupload params.
|
94 |
+
*
|
95 |
+
* @since 1.2.0
|
96 |
+
*/
|
97 |
+
public function filter_plupload_params( $plupload_params ) {
|
98 |
+
|
99 |
+
$plupload_params['action'] = 'tux_big_file_uploads';
|
100 |
+
return $plupload_params;
|
101 |
|
102 |
}
|
103 |
|
116 |
if ( $tuxbfu_max_retries < 1 ) {
|
117 |
$tuxbfu_max_retries = 5;
|
118 |
}
|
119 |
+
$plupload_settings['url'] = admin_url( 'admin-ajax.php' );
|
120 |
$plupload_settings['filters']['max_file_size'] = $this->filter_upload_size_limit('') . 'b';
|
121 |
$plupload_settings['chunk_size'] = $tuxbfu_chunk_size . 'kb';
|
122 |
$plupload_settings['max_retries'] = $tuxbfu_max_retries;
|
149 |
*/
|
150 |
public function filter_upload_size_limit( $unused ) {
|
151 |
|
152 |
+
$tuxbfu_max_upload_size = intval( get_option( 'tuxbfu_max_upload_size', 0 ) ) * 1048576;
|
153 |
+
if ( $tuxbfu_max_upload_size < 0 ) {
|
154 |
+
$tuxbfu_max_upload_size = 0;
|
155 |
+
}
|
156 |
+
|
157 |
+
if ( $tuxbfu_max_upload_size > 0 ) {
|
158 |
+
return $tuxbfu_max_upload_size;
|
159 |
+
}
|
160 |
+
|
161 |
$bytes = disk_free_space( sys_get_temp_dir() );
|
162 |
if ( $bytes === false ) {
|
163 |
$bytes = 0;
|
175 |
*/
|
176 |
public function settings_api_init() {
|
177 |
|
178 |
+
add_settings_field(
|
179 |
+
'tuxbfu_max_upload_size',
|
180 |
+
__( 'Maximum Upload Size (MB) (0 for no limit)', 'tuxedo-big-file-uploads' ),
|
181 |
+
array( $this, 'settings_max_upload_size_callback' ),
|
182 |
+
'media',
|
183 |
+
'uploads'
|
184 |
+
);
|
185 |
add_settings_field(
|
186 |
'tuxbfu_chunk_size',
|
187 |
__( 'Chunk Size (kb)', 'tuxedo-big-file-uploads' ),
|
196 |
'media',
|
197 |
'uploads'
|
198 |
);
|
199 |
+
register_setting( 'media', 'tuxbfu_max_upload_size', 'intval' );
|
200 |
register_setting( 'media', 'tuxbfu_chunk_size', 'intval' );
|
201 |
register_setting( 'media', 'tuxbfu_max_retries', 'intval' );
|
202 |
|
203 |
}
|
204 |
|
205 |
+
/**
|
206 |
+
* Output max upload size input control.
|
207 |
+
*
|
208 |
+
* @since 1.2.0
|
209 |
+
*/
|
210 |
+
public function settings_max_upload_size_callback() {
|
211 |
+
|
212 |
+
$tuxbfu_max_upload_size = intval( get_option( 'tuxbfu_max_upload_size', 0 ) );
|
213 |
+
if ( $tuxbfu_max_upload_size < 0 ) {
|
214 |
+
$tuxbfu_max_upload_size = 0;
|
215 |
+
}
|
216 |
+
$tuxbfu_max_upload_size = esc_attr( $tuxbfu_max_upload_size );
|
217 |
+
echo "<input type='text' name='tuxbfu_max_upload_size' value='{$tuxbfu_max_upload_size}' />";
|
218 |
+
|
219 |
+
}
|
220 |
+
|
221 |
/**
|
222 |
* Output chunk size input control.
|
223 |
*
|
250 |
|
251 |
}
|
252 |
|
253 |
+
/**
|
254 |
+
* Return a file's mime type.
|
255 |
+
*
|
256 |
+
* @since 1.2.0
|
257 |
+
*
|
258 |
+
* @param string $filename File name.
|
259 |
+
* @return var string $mimetype Mime type.
|
260 |
+
*/
|
261 |
+
public function get_mime_content_type( $filename ) {
|
262 |
+
|
263 |
+
if ( function_exists( 'mime_content_type' ) ) {
|
264 |
+
return mime_content_type( $filename );
|
265 |
+
}
|
266 |
+
|
267 |
+
if ( function_exists( 'finfo_open' ) ) {
|
268 |
+
$finfo = finfo_open( FILEINFO_MIME );
|
269 |
+
$mimetype = finfo_file( $finfo, $filename );
|
270 |
+
finfo_close( $finfo );
|
271 |
+
return $mimetype;
|
272 |
+
} else {
|
273 |
+
ob_start();
|
274 |
+
system( 'file -i -b ' . $filename );
|
275 |
+
$output = ob_get_clean();
|
276 |
+
$output = explode( '; ', $output );
|
277 |
+
if ( is_array( $output ) ) {
|
278 |
+
$output = $output[0];
|
279 |
+
}
|
280 |
+
return $output;
|
281 |
+
}
|
282 |
+
|
283 |
+
}
|
284 |
+
|
285 |
+
/**
|
286 |
+
* AJAX chunk receiver.
|
287 |
+
* Ajax callback for plupload to handle chunked uploads.
|
288 |
+
* Based on code by Davit Barbakadze
|
289 |
+
* https://gist.github.com/jayarjo/5846636
|
290 |
+
*
|
291 |
+
* @since 1.2.0
|
292 |
+
*/
|
293 |
+
public function ajax_chunk_receiver() {
|
294 |
+
|
295 |
+
/** Check that we have an upload and there are no errors. */
|
296 |
+
if ( empty( $_FILES ) || $_FILES['async-upload']['error'] ) {
|
297 |
+
/** Failed to move uploaded file. */
|
298 |
+
die();
|
299 |
+
}
|
300 |
+
|
301 |
+
/** Authenticate user. */
|
302 |
+
if ( ! is_user_logged_in() || ! current_user_can( 'upload_files' ) ) {
|
303 |
+
die();
|
304 |
+
}
|
305 |
+
check_admin_referer( 'media-form' );
|
306 |
+
|
307 |
+
/** Check and get file chunks. */
|
308 |
+
$chunk = isset( $_REQUEST['chunk']) ? intval( $_REQUEST['chunk'] ) : 0;
|
309 |
+
$chunks = isset( $_REQUEST['chunks']) ? intval( $_REQUEST['chunks'] ) : 0;
|
310 |
+
|
311 |
+
/** Get file name and path + name. */
|
312 |
+
$fileName = isset( $_REQUEST['name'] ) ? $_REQUEST['name'] : $_FILES['async-upload']['name'];
|
313 |
+
$filePath = dirname( $_FILES['async-upload']['tmp_name'] ) . '/' . md5( $fileName );
|
314 |
+
|
315 |
+
$tuxbfu_max_upload_size = intval( get_option( 'tuxbfu_max_upload_size', 0 ) * 1048576 );
|
316 |
+
if ( $tuxbfu_max_upload_size < 0 ) {
|
317 |
+
$tuxbfu_max_upload_size = 0;
|
318 |
+
}
|
319 |
+
|
320 |
+
if ( $tuxbfu_max_upload_size > 0 && file_exists( "{$filePath}.part" ) && filesize( "{$filePath}.part" ) + filesize( $_FILES['async-upload']['tmp_name'] ) > $tuxbfu_max_upload_size ) {
|
321 |
+
|
322 |
+
if ( ! $chunks || $chunk == $chunks - 1 ) {
|
323 |
+
@unlink( "{$filePath}.part" );
|
324 |
+
|
325 |
+
if ( ! isset( $_REQUEST['short'] ) || ! isset( $_REQUEST['type'] ) ) {
|
326 |
+
|
327 |
+
echo wp_json_encode( array(
|
328 |
+
'success' => false,
|
329 |
+
'data' => array(
|
330 |
+
'message' => __( 'The file size has exceeded the maximum file size setting.', 'tuxed-big-file-uploads' ),
|
331 |
+
'filename' => $_FILES['async-upload']['name'],
|
332 |
+
)
|
333 |
+
) );
|
334 |
+
wp_die();
|
335 |
+
|
336 |
+
} else {
|
337 |
+
|
338 |
+
echo '<div class="error-div error">
|
339 |
+
<a class="dismiss" href="#" onclick="jQuery(this).parents(\'div.media-item\').slideUp(200, function(){jQuery(this).remove();});">' . __( 'Dismiss' ) . '</a>
|
340 |
+
<strong>' . sprintf( __( '“%s” has failed to upload.' ), esc_html( $_FILES['async-upload']['name'] ) ) . '<br />' . __( 'The file size has exceeded the maximum file size setting.', 'tuxed-big-file-uploads' ) . '</strong><br />' .
|
341 |
+
esc_html( $id->get_error_message() ) . '</div>';
|
342 |
+
|
343 |
+
}
|
344 |
+
|
345 |
+
}
|
346 |
+
|
347 |
+
die();
|
348 |
+
|
349 |
+
}
|
350 |
+
|
351 |
+
/** Open temp file. */
|
352 |
+
$out = @fopen( "{$filePath}.part", $chunk == 0 ? 'wb' : 'ab' );
|
353 |
+
if ( $out ) {
|
354 |
+
|
355 |
+
/** Read binary input stream and append it to temp file. */
|
356 |
+
$in = @fopen( $_FILES['async-upload']['tmp_name'], 'rb' );
|
357 |
+
|
358 |
+
if ( $in ) {
|
359 |
+
while ( $buff = fread( $in, 4096 ) ) {
|
360 |
+
fwrite( $out, $buff );
|
361 |
+
}
|
362 |
+
} else {
|
363 |
+
/** Failed to open input stream. */
|
364 |
+
/** Attempt to clean up unfinished output. */
|
365 |
+
@fclose( $out );
|
366 |
+
@unlink( "{$filePath}.part" );
|
367 |
+
die();
|
368 |
+
}
|
369 |
+
|
370 |
+
@fclose( $in );
|
371 |
+
@fclose( $out );
|
372 |
+
|
373 |
+
@unlink( $_FILES['async-upload']['tmp_name'] );
|
374 |
+
|
375 |
+
} else {
|
376 |
+
/** Failed to open output stream. */
|
377 |
+
die();
|
378 |
+
}
|
379 |
+
|
380 |
+
/** Check if file has finished uploading all parts. */
|
381 |
+
if ( ! $chunks || $chunk == $chunks - 1 ) {
|
382 |
+
|
383 |
+
/** Recreate upload in $_FILES global and pass off to WordPress. */
|
384 |
+
rename( "{$filePath}.part", $_FILES['async-upload']['tmp_name'] );
|
385 |
+
$_FILES['async-upload']['name'] = $fileName;
|
386 |
+
$_FILES['async-upload']['size'] = filesize( $_FILES['async-upload']['tmp_name'] );
|
387 |
+
$_FILES['async-upload']['type'] = $this->get_mime_content_type( $_FILES['async-upload']['tmp_name'] );
|
388 |
+
header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
|
389 |
+
|
390 |
+
if ( ! isset( $_REQUEST['short'] ) || ! isset( $_REQUEST['type'] ) ) {
|
391 |
+
|
392 |
+
send_nosniff_header();
|
393 |
+
nocache_headers();
|
394 |
+
wp_ajax_upload_attachment();
|
395 |
+
die( '0' );
|
396 |
+
|
397 |
+
} else {
|
398 |
+
|
399 |
+
$post_id = 0;
|
400 |
+
if ( isset( $_REQUEST['post_id'] ) ) {
|
401 |
+
$post_id = absint( $_REQUEST['post_id'] );
|
402 |
+
if ( ! get_post( $post_id ) || ! current_user_can( 'edit_post', $post_id ) )
|
403 |
+
$post_id = 0;
|
404 |
+
}
|
405 |
+
|
406 |
+
$id = media_handle_upload( 'async-upload', $post_id );
|
407 |
+
if ( is_wp_error( $id ) ) {
|
408 |
+
echo '<div class="error-div error">
|
409 |
+
<a class="dismiss" href="#" onclick="jQuery(this).parents(\'div.media-item\').slideUp(200, function(){jQuery(this).remove();});">' . __( 'Dismiss' ) . '</a>
|
410 |
+
<strong>' . sprintf( __( '“%s” has failed to upload.' ), esc_html( $_FILES['async-upload']['name'] ) ) . '</strong><br />' .
|
411 |
+
esc_html( $id->get_error_message() ) . '</div>';
|
412 |
+
exit;
|
413 |
+
}
|
414 |
+
|
415 |
+
if ( isset( $_REQUEST['short'] ) && $_REQUEST['short'] ) {
|
416 |
+
// Short form response - attachment ID only.
|
417 |
+
echo $id;
|
418 |
+
} elseif ( isset( $_REQUEST['type'] ) ) {
|
419 |
+
// Long form response - big chunk o html.
|
420 |
+
$type = $_REQUEST['type'];
|
421 |
+
|
422 |
+
/**
|
423 |
+
* Filter the returned ID of an uploaded attachment.
|
424 |
+
*
|
425 |
+
* The dynamic portion of the hook name, `$type`, refers to the attachment type,
|
426 |
+
* such as 'image', 'audio', 'video', 'file', etc.
|
427 |
+
*
|
428 |
+
* @since 1.2.0
|
429 |
+
*
|
430 |
+
* @param int $id Uploaded attachment ID.
|
431 |
+
*/
|
432 |
+
echo apply_filters( "async_upload_{$type}", $id );
|
433 |
+
}
|
434 |
+
|
435 |
+
}
|
436 |
+
|
437 |
+
}
|
438 |
+
|
439 |
+
die();
|
440 |
+
|
441 |
+
}
|
442 |
+
|
443 |
}
|
444 |
|
445 |
/** Instantiate the plugin class. */
|
uninstall.php
CHANGED
@@ -14,5 +14,6 @@ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
|
14 |
}
|
15 |
|
16 |
/** Delete options. */
|
|
|
17 |
delete_option( 'tuxbfu_chunk_size' );
|
18 |
delete_option( 'tuxbfu_max_retries' );
|
14 |
}
|
15 |
|
16 |
/** Delete options. */
|
17 |
+
delete_option( 'tuxbfu_max_upload_size' );
|
18 |
delete_option( 'tuxbfu_chunk_size' );
|
19 |
delete_option( 'tuxbfu_max_retries' );
|