Re-added file extension restriction ACP option

Closes #3918
v1.18.x
Julian Lam 9 years ago
parent 7e1a84850c
commit 37b13b4879

@ -125,6 +125,14 @@ function uploadFile(uid, uploadedFile, callback) {
return callback(new Error('[[error:file-too-big, ' + meta.config.maximumFileSize + ']]')); return callback(new Error('[[error:file-too-big, ' + meta.config.maximumFileSize + ']]'));
} }
if (meta.config.hasOwnProperty('allowedFileExtensions')) {
var allowed = meta.config.allowedFileExtensions.split(',').filter(Boolean);
var extension = path.extname(uploadedFile.name).slice(1);
if (allowed.length > 0 && allowed.indexOf(extension) === -1) {
return callback(new Error('[[error:invalid-file-type, ' + allowed.join(', ') + ']]'));
}
}
var filename = uploadedFile.name || 'upload'; var filename = uploadedFile.name || 'upload';
filename = Date.now() + '-' + validator.escape(filename).substr(0, 255); filename = Date.now() + '-' + validator.escape(filename).substr(0, 255);

@ -132,13 +132,18 @@
<span class="mdl-switch__label"><strong>Allow users to upload regular files</strong></span> <span class="mdl-switch__label"><strong>Allow users to upload regular files</strong></span>
</label> </label>
</div> </div>
<div class="checkbox"> <div class="checkbox">
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"> <label class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
<input class="mdl-switch__input" type="checkbox" data-field="privateUploads"> <input class="mdl-switch__input" type="checkbox" data-field="privateUploads">
<span class="mdl-switch__label"><strong>Make uploaded files private</strong></span> <span class="mdl-switch__label"><strong>Make uploaded files private</strong></span>
</label> </label>
</div> </div>
<strong>Maximum File Size</strong><br /> <input type="text" class="form-control" value="2048" data-field="maximumFileSize"><br />
<div class="form-group">
<label for="maximumFileSize">Maximum File Size</label>
<input type="text" class="form-control" value="2048" data-field="maximumFileSize">
</div>
<div class="checkbox"> <div class="checkbox">
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"> <label class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
@ -146,7 +151,20 @@
<span class="mdl-switch__label"><strong>Allow users to upload topic thumbnails</strong></span> <span class="mdl-switch__label"><strong>Allow users to upload topic thumbnails</strong></span>
</label> </label>
</div> </div>
<strong>Topic Thumb Size</strong><br /> <input type="text" class="form-control" value="120" data-field="topicThumbSize"> <br />
<div class="form-group">
<label for="topicThumbSize">Topic Thumb Size</label>
<input type="text" class="form-control" value="120" data-field="topicThumbSize">
</div>
<div class="form-group">
<label for="allowedFileExtensions">Allowed File Extensions</label>
<input type="text" class="form-control" value="" data-field="allowedFileExtensions" />
<p class="help-block">
Enter comma-separated list of file extensions here (e.g. <code>pdf,xls,doc</code>).
An empty list means all extensions are allowed.
</p>
</div>
</form> </form>
</div> </div>
</div> </div>

Loading…
Cancel
Save