$29 GRAYBYTE WORDPRESS FILE MANAGER $85

SERVER : premium201.web-hosting.com #1 SMP Wed Mar 26 12:08:09 UTC 2025
SERVER IP : 172.67.162.162 | ADMIN IP 216.73.216.51
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/home/bravetechrwanda/itiministry.org/plugins/give/src/Framework/ValidationRules/Rules/

HOME
Current File : /home/bravetechrwanda/itiministry.org/plugins/give/src/Framework/ValidationRules/Rules//File.php
<?php
declare(strict_types=1);

namespace Give\Framework\ValidationRules\Rules;

use Closure;
use Give\Framework\Http\Types\UploadedFile;
use Give\Vendors\StellarWP\Validation\Contracts\ValidatesOnFrontEnd;
use Give\Vendors\StellarWP\Validation\Contracts\ValidationRule;

/**
 * @since 2.32.0
 */
class File implements ValidationRule, ValidatesOnFrontEnd
{
    /**
     * The size, in bytes, of the uploaded file
     *
     * @var int
     */
    protected $maxSize;

    /**
     * @var string[]
     */
    protected $allowedMimeTypes;

    /**
     * @since 2.32.0
     */
    public static function id(): string
    {
        return 'file';
    }

    /**
     * @since 2.32.0
     */
    public function maxSize(int $maxSize): ValidationRule
    {
        $this->maxSize = $maxSize;

        return $this;
    }

    /**
     * @since 2.32.0
     */
    public function getMaxSize(): int
    {
        return $this->maxSize ?? wp_max_upload_size();
    }

    /**
     * @since 2.32.0
     */
    public function allowedMimeTypes(array $allowedMimeTypes): ValidationRule
    {
        $this->allowedMimeTypes = $allowedMimeTypes;

        return $this;
    }

    /**
     * @since 2.32.0
     *
     * @return string[]
     */
    public function getAllowedMimeTypes(): array
    {
        return $this->allowedMimeTypes ?? get_allowed_mime_types();
    }

    /**
     * @since 2.32.0
     **/
    public function __invoke($value, Closure $fail, string $key, array $values)
    {
        try {
            $file = UploadedFile::fromArray($value);

            if (!$file->isUploadedFile()) {
                $fail(sprintf(__('%s must be a valid file.', 'give'), '{field}'));
            }

            // check against both the allowed mime types defined by the file rule and the server
            if (!in_array($file->getMimeType(), $this->getAllowedMimeTypes(), true) ||
                !in_array($file->getMimeType(), get_allowed_mime_types(), true)) {
                $fail(sprintf(__('%s must be a valid file type.', 'give'), '{field}'));
            }

            // check against both the max upload size defined by the file rule and the server
            if ($file->getSize() > $this->getMaxSize() || $file->getSize() > wp_max_upload_size()) {
                $fail(
                    sprintf(__('%s must be less than or equal to %d bytes.', 'give'), '{field}', $this->getMaxSize())
                );
            }

            if ($file->getError() !== UPLOAD_ERR_OK) {
                $fail(sprintf(__('%s must be a valid file.', 'give'), '{field}'));
            }
        } catch (\Throwable $e) {
            $fail($e->getMessage());
        }
    }

    /**
     * @since 2.32.0
     */
    public static function fromString(string $options = null): ValidationRule
    {
        return new self();
    }

    public function serializeOption()
    {
        return null;
    }
}


Current_dir [ WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
1 Jan 1970 12.00 AM
root / root
0
AllowedTypes.php
2.819 KB
19 Jan 2023 12.19 AM
bravetechrwanda / bravetechrwanda
0644
File.php
2.838 KB
16 Oct 2023 9.55 PM
bravetechrwanda / bravetechrwanda
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF Static GIF