Are .csv Import Entries not working for anyone else? [RESOLVED]

No matter what I try, I just can’t get the Import Entries plugin to work. (Solution at bottom of this post)
However, the Export Entries works just fine.
I am currently using WordPress 5.0.2
GravityView - Gravity Forms Import Entries Version 1.3.5.1

Before making any changes to try and fix this I get the Error Mssg:
“Sorry, this file type is not permitted for security reasons.”

After attempting to fix the issue the Exclamation Mark alert icon displayed next to ‘Choose Files’ button > Mssg is “Validation Error. This field is required.” after clicking on ‘Upload File’ button.

WHAT I’VE DONE SO FAR
1. Tried using the Plugin ‘Disable Real MIME Check’
2. Added code to functions.php allowing for specific mime type uploads (see below)
3. Added code to wp-config.php to allow for unfiltered uploads.
4. Deactivated all plugins and re-attempted import of .csv file.
5. Enabled Gravity Forms logging > https://docs.gravityforms.com/logging-and-debugging/
6. Created a new database and installed older WordPress version 4.7.0,
then implemented same suggested fixes listed above only to get the same results.

(ADDED THIS CODE TO wp-config) >>

define(‘ALLOW_UNFILTERED_UPLOADS’, true);

ADDED THIS CODE TO functions.php

============
function my_custom_upload_mimes($mimes = array()) {
// Add a key and value for the CSV file type
$mimes[‘csv’] = “text/csv”;

return $mimes;

}

add_action(‘upload_mimes’, ‘my_custom_upload_mimes’);

============

Any suggestions or a fix that works would be greatly appreciated…

Thx

R.Price

====================================

SOLUTION:

Not sure why the code mods below didn’t work for me, but the following DID WORK

Source: https://gist.github.com/rmpel/e1e2452ca06ab621fe061e0fde7ae150

Add this code to your Theme’s functions.php file:

<?php /** * Restore CSV upload functionality for WordPress 4.9.9 and up */ add_filter('wp_check_filetype_and_ext', function($values, $file, $filename, $mimes) { if ( extension_loaded( 'fileinfo' ) ) { // with the php-extension, a CSV file is issues type text/plain so we fix that back to // text/csv by trusting the file extension. $finfo = finfo_open( FILEINFO_MIME_TYPE ); $real_mime = finfo_file( $finfo, $file ); finfo_close( $finfo ); if ( $real_mime === 'text/plain' && preg_match( '/\.(csv)$/i', $filename ) ) { $values['ext'] = 'csv'; $values['type'] = 'text/csv'; } } else { // without the php-extension, we probably don't have the issue at all, but just to be sure... if ( preg_match( '/\.(csv)$/i', $filename ) ) { $values['ext'] = 'csv'; $values['type'] = 'text/csv'; } } return $values; }, PHP_INT_MAX, 4);

I recommend opening a support ticket with GravityView to ensure you get this resolved.

WordPress’s latest update saw further restrictions on uploads. The following code overrides this behaviour for JSON files:

add_filter( 'upload_mimes', function( $mime_types ) {
	$mime_types['json'] = 'application/json'; // Adding .json extension

	return $mime_types;
}, 1, 1 );

add_filter( 'wp_check_filetype_and_ext', function( $mime, $file, $filename, $mimes ) {

	$wp_filetype = wp_check_filetype( $filename, $mimes );
	if ( in_array( $wp_filetype['ext'], [ 'json' ] ) ) {
		$mime['ext']  = true;
		$mime['type'] = true;
	}

	return $mime;
}, 10, 4 );

You might want to limit this code to a specific role as it applies to any user (logged in or otherwise).

2 Likes

Thanks for the suggestion Jake…

I inserted your code in my theme’s functions.php file, but I’m still getting a “Validation Error: This field is required.” Warning after clicking the Upload File button.

Is it working for you?

I think Rafael w/support is looking into it.

I’ll follow-up when it gets resolved.

Thx again,

-R

1 Like

I was able to adapt (only in a tiny little way) Jake’s code from here to allow the upload of *.ai files:

add_filter( 'upload_mimes', function( $mime_types ) {
	$mime_types['ai'] = 'application/postscript'; // Adding .ai extension

	return $mime_types;
}, 1, 1 );

add_filter( 'wp_check_filetype_and_ext', function( $mime, $file, $filename, $mimes ) {

	$wp_filetype = wp_check_filetype( $filename, $mimes );
	if ( in_array( $wp_filetype['ext'], [ 'ai' ] ) ) {
		$mime['ext']  = true;
		$mime['type'] = true;
	}

	return $mime;
}, 10, 4 );
1 Like

Upgrading wp to 5.0.3 solved the problem in my case, it’s a known bug.

1 Like

Yes. WordPress 5.0.3 included a fix for this issue.

https://core.trac.wordpress.org/ticket/45615

1 Like