Add option to pass acceptable mime types to
MD_STD_IN::move_uploaded_file
This commit is contained in:
parent
6adf0ee0a2
commit
d53303e617
|
@ -675,7 +675,7 @@ final class MD_STD {
|
||||||
*/
|
*/
|
||||||
public static function string_to_color_code(string $str):string {
|
public static function string_to_color_code(string $str):string {
|
||||||
|
|
||||||
$code = substr(dechex(crc32($str)), 0, 6);
|
$code = \substr(\dechex(\crc32($str)), 0, 6);
|
||||||
return $code;
|
return $code;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -689,11 +689,11 @@ final class MD_STD {
|
||||||
*/
|
*/
|
||||||
public static function check_is_writable(string $dir):void {
|
public static function check_is_writable(string $dir):void {
|
||||||
|
|
||||||
if (is_dir($dir) === false) {
|
if (\is_dir($dir) === false) {
|
||||||
throw new MDFileDoesNotExist("Directory " . $dir . " does not exist");
|
throw new MDFileDoesNotExist("Directory " . $dir . " does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_writable($dir) === false) {
|
if (\is_writable($dir) === false) {
|
||||||
throw new MDFileIsNotWritable("Directory " . $dir . " is not writable");
|
throw new MDFileIsNotWritable("Directory " . $dir . " is not writable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -322,13 +322,18 @@ final class MD_STD_IN {
|
||||||
* Wrapper around move_uploaded_file that throws errors in case the upload failed
|
* Wrapper around move_uploaded_file that throws errors in case the upload failed
|
||||||
* for an identifiable reason.
|
* for an identifiable reason.
|
||||||
*
|
*
|
||||||
* @param string $filename Name of the file to upload.
|
* @param string $filename Name of the file to upload.
|
||||||
* @param string $destination Destination to move the file to.
|
* @param string $destination Destination to move the file to.
|
||||||
|
* @param array<string> $mime_types Optional array of acceptable mime types. If this is
|
||||||
|
* not empty, the file will be checked for having one
|
||||||
|
* of the given mime types. If it does not, an error
|
||||||
|
* will be thrown.
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function move_uploaded_file(string $filename, string $destination):bool {
|
public static function move_uploaded_file(string $filename, string $destination, array $mime_types = []):bool {
|
||||||
|
|
||||||
|
MD_STD::ensure_file($filename, $mime_types);
|
||||||
MD_STD::check_is_writable(dirname($destination));
|
MD_STD::check_is_writable(dirname($destination));
|
||||||
|
|
||||||
if (!(\move_uploaded_file($filename, $destination))) {
|
if (!(\move_uploaded_file($filename, $destination))) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user