Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid extension alert and clear input #15595

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions js/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ function matchFile (fname) {
var len = fnameArray.length;
if (len !== 0) {
var extension = fnameArray[len - 1];
// list of valid extension
var validExt = ['csv','sql','xml','txt','ods','atx','ain','aih','dbf','gz','zip','bz2'];
if (!validExt.includes(extension)) {
// alert error response
alert(
'Invalid file format . Valid file format (\'csv\',\'sql\',\'xml\',\'txt\',\'ods\',\'atx\',\'ain\',\'aih\',\'dbf\',\'gz\',\'zip\',\'bz2\')\n');
williamdes marked this conversation as resolved.
Show resolved Hide resolved
// clear the input field to force user to upload again
$('#input_import_file').val('');
}
if (extension === 'gz' || extension === 'bz2' || extension === 'zip') {
len--;
}
Expand Down
25 changes: 25 additions & 0 deletions libraries/entry_points/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,29 @@

// handle filenames
if (isset($_FILES['import_file'])) {
$fileName = $_FILES['import_file']["name"];
$explodeByDot = explode(".",$fileName);
$sizeOfExplodedArray= sizeof($explodeByDot);
if($sizeOfExplodedArray < 2){
$message = PhpMyAdmin\Message::error(
__(
'Invalid file .'
)
);
$import->stop($message);
} else {
$extension =$explodeByDot[$sizeOfExplodedArray-1];
$validExtension = array('csv','sql','xml','txt','ods','atx','ain','aih','dbf','gz','zip','bz2');
if (!in_array($extension,$validExtension)) {
$message = PhpMyAdmin\Message::error(
__(
('Invalid file format . Valid file format (\'csv\',\'sql\',\'xml\',\'txt\',\'ods\',\'atx\',\'ain\',\'aih\',\'dbf\',\'gz\',\'zip\',\'bz2\')')
)
);
$import->stop($message);
}
}

$import_file = $_FILES['import_file']['tmp_name'];
$import_file_name = $_FILES['import_file']['name'];
}
Expand Down Expand Up @@ -487,7 +510,9 @@
/**
* Handle file compression
*/

$import_handle = new File($import_file);

$import_handle->checkUploadedFile();
if ($import_handle->isError()) {
$import->stop($import_handle->getError());
Expand Down