[WordPress] More on Working with CSV Files in WordPress
<?php | |
private function is_valid_mime_type( $file ) { | |
$mime_types = array( | |
'application/vnd.ms-excel', | |
'text/plain', | |
'text/csv', | |
'text/tsv', | |
); | |
return in_array( mime_content_type( $file ), $mime_types ); | |
} |
<?php | |
private function is_valid_extension( $file ) { | |
return ( 'csv' === pathinfo( $file, PATHINFO_EXTENSION ) ); | |
} |
<?php | |
public function approves( $file ) { | |
return | |
$this->is_valid_extension( $file ) && $this->is_valid_mime_type( $file ); | |
} |
<?php | |
namespace Acme\Utility\CSV; | |
class Validator { | |
public function approves( $file ) { | |
return | |
$this->is_valid_extension( $file ) && $this->is_valid_mime_type( $file ); | |
} | |
private function is_valid_mime_type( $file ) { | |
$mime_types = array( | |
'application/vnd.ms-excel', | |
'text/plain', | |
'text/csv', | |
'text/tsv', | |
); | |
return in_array( mime_content_type( $file ), $mime_types ); | |
} | |
private function is_valid_extension( $file ) { | |
return ( 'csv' === pathinfo( $file, PATHINFO_EXTENSION ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment