2019-05-09 06:54:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
2020-03-24 17:56:32 +00:00
|
|
|
namespace Appwrite\Storage\Validators;
|
2019-05-09 06:54:39 +00:00
|
|
|
|
|
|
|
|
use Utopia\Validator;
|
|
|
|
|
|
|
|
|
|
class FileName extends Validator
|
|
|
|
|
{
|
|
|
|
|
public function getDescription()
|
|
|
|
|
{
|
|
|
|
|
return 'Filename is not valid';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-09-06 17:04:26 +00:00
|
|
|
* The file name can only contain "a-z", "A-Z", "0-9" and "-" and not empty.
|
|
|
|
|
*
|
|
|
|
|
* @param string $name
|
2019-05-09 06:54:39 +00:00
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isValid($name)
|
|
|
|
|
{
|
2019-09-06 17:04:26 +00:00
|
|
|
if (empty($name)) {
|
2019-05-09 06:54:39 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 17:04:26 +00:00
|
|
|
if (!preg_match('/^[a-zA-Z0-9.]+$/', $name)) {
|
2019-05-09 06:54:39 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|