Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created September 7, 2016 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/ffe1a5a33e2ba80792cb38d6a6e0c3bc to your computer and use it in GitHub Desktop.
Save tommcfarlin/ffe1a5a33e2ba80792cb38d6a6e0c3bc to your computer and use it in GitHub Desktop.
[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