-
-
Save tommcfarlin/ffe1a5a33e2ba80792cb38d6a6e0c3bc to your computer and use it in GitHub Desktop.
[WordPress] More on Working with CSV Files in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
private function is_valid_extension( $file ) { | |
return ( 'csv' === pathinfo( $file, PATHINFO_EXTENSION ) ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function approves( $file ) { | |
return | |
$this->is_valid_extension( $file ) && $this->is_valid_mime_type( $file ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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