Merge pull request #15811 from danielhuesken/fix_importer_filtype

Importer fix file type detection on local path
This commit is contained in:
Mike Jolley 2017-06-27 15:24:36 +01:00 committed by GitHub
commit f6240a1626
1 changed files with 5 additions and 5 deletions

View File

@ -228,19 +228,19 @@ class WC_Product_CSV_Importer_Controller {
* @return string|WP_Error
*/
public function handle_upload() {
$valid_filetypes = apply_filters( 'woocommerce_csv_product_import_valid_filetypes', array( 'text/csv', 'text/plain' ) );
$valid_filetypes = apply_filters( 'woocommerce_csv_product_import_valid_filetypes', array( 'csv' => 'text/csv', 'txt' => 'text/plain' ) );
if ( empty( $_POST['file_url'] ) ) {
if ( ! isset( $_FILES['import'] ) ) {
return new WP_Error( 'woocommerce_product_csv_importer_upload_file_empty', __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.', 'woocommerce' ) );
}
if ( ! in_array( $_FILES['import']['type'], $valid_filetypes ) ) {
$filetype = wp_check_filetype( $_FILES['import']['name'], $valid_filetypes );
if ( ! in_array( $filetype['type'], $valid_filetypes ) ) {
return new WP_Error( 'woocommerce_product_csv_importer_upload_file_invalid', __( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) );
}
$overrides = array( 'test_form' => false, 'test_type' => false );
$_FILES['import']['name'] .= '.txt';
$overrides = array( 'test_form' => false, 'mimes' => $valid_filetypes );
$upload = wp_handle_upload( $_FILES['import'], $overrides );
if ( isset( $upload['error'] ) ) {
@ -268,7 +268,7 @@ class WC_Product_CSV_Importer_Controller {
return $upload['file'];
} elseif ( file_exists( ABSPATH . $_POST['file_url'] ) ) {
$filetype = wp_check_filetype( ABSPATH . $_POST['file_url'] );
$filetype = wp_check_filetype( ABSPATH . $_POST['file_url'], $valid_filetypes );
if ( ! in_array( $filetype['type'], $valid_filetypes ) ) {
return new WP_Error( 'woocommerce_product_csv_importer_upload_file_invalid', __( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) );
}