easy-digital-downloads icon indicating copy to clipboard operation
easy-digital-downloads copied to clipboard

Importing Downloads from an EDD export is failing on mime check

Open mihaijoldis opened this issue 2 years ago • 1 comments

Bug Report

Expected behavior

After I export Downloads in EDD I should be able to import them back.

Actual behavior

The mime type check is failing

Steps to reproduce the behavior

  1. Export Downloads using the Downloads > reports > export page
  2. Go to Downloads > tools > Import and select the exported CSV file.

The first problem the user had was this error right when uploading the file "Sorry, you are not allowed to upload this file type.". Got this solved by adding define('ALLOW_UNFILTERED_UPLOADS', true); After that, the Field mapping was showing, and when running the import another error was visible "The file you uploaded does not appear to be a CSV file".

The issue is coming from this line https://github.com/awesomemotive/easy-digital-downloads/blob/main/includes/admin/import/import-functions.php#L119

mime_content_type( $file ) returns text/html but that is not set in the edd_importer_accepted_mime_types(). The workaround was to remove the if clause and leave just:

		if ( wp_check_filetype( $file, edd_importer_accepted_mime_types() ) ) {
			$mime_type_allowed = true;
		}

Information (if a specific version is affected):

PHP Version: 7+

EDD Version (or branch): main

WordPress Version: latest

Any other relevant information: From a bit of googling, I believe sometimes, the mime type of the exported file can be set as text/html if there are HTML elements inside the file. https://secure.helpscout.net/conversation/2021810577/2192991?folderId=5762562

mihaijoldis avatar Sep 28 '22 16:09 mihaijoldis

Confirmed the same fix (removing IF condition) on a customer's site.

mihaijoldis avatar Sep 28 '22 16:09 mihaijoldis