| @@ -131,15 +131,22 @@ | ||
| 131 | 131 | /** |
| 132 | 132 | * FileUploaded event |
| 133 | 133 | */ |
| 134 | 134 | Uploader.prototype.FileUploaded = function( uploader, file, r ) { |
| 135 | - var input, data; | |
| 135 | + var input, data, message; | |
| 136 | 136 | |
| 137 | 137 | r = $.parseJSON( r.response ); |
| 138 | 138 | |
| 139 | 139 | if ( ! r.success ) { |
| 140 | 140 | |
| 141 | - this.add_image_error( file, CHARITABLE_UPLOAD_VARS.upload_problem.replace('%s', file.name) ); | |
| 141 | + // Show the server's own reason when it sends one - a refusal ("please log in") | |
| 142 | + // or a rejected file type is not something retrying can fix, so the generic | |
| 143 | + // "please try again" is only the fallback. Only data.message is trusted here: | |
| 144 | + // data.error carries WordPress core's raw upload errors, which name php.ini | |
| 145 | + // directives and server paths and must not be shown to public visitors. | |
| 146 | + message = r.data && typeof r.data.message === 'string' ? r.data.message : ''; | |
| 147 | + | |
| 148 | + this.add_image_error( file, message || CHARITABLE_UPLOAD_VARS.upload_problem.replace('%s', file.name) ); | |
| 142 | 149 | return; |
| 143 | 150 | |
| 144 | 151 | } |
| 145 | 152 | |
| @@ -240,8 +247,16 @@ | ||
| 240 | 247 | * @return void |
| 241 | 248 | */ |
| 242 | 249 | Uploader.prototype.add_image_error = function( file, msg ) { |
| 243 | 250 | var self = this; |
| 251 | + | |
| 252 | + // FileFiltered counted this file against max_file_uploads before it was sent. A | |
| 253 | + // failed upload never becomes a preview, so nothing else gives the slot back, and | |
| 254 | + // without this the next attempt is rejected client-side with the "you have already | |
| 255 | + // uploaded the maximum number of files" alert and the user is stuck until reload. | |
| 256 | + if ( self.uploaded > 0 ) { | |
| 257 | + self.uploaded -= 1; | |
| 258 | + } | |
| 244 | 259 | |
| 245 | 260 | self.$dropzone.fadeIn( 300 ); |
| 246 | 261 | |
| 247 | 262 | self.$loader.find( '[data-file-id=' + file.id + ']' ).addClass( 'error' ).text( msg ).delay( 5000 ).fadeOut( 300, function(){ |