Classes

File io/http/upload/UploadedFile.class.php

File io/http/upload/UploadedFile.class.php

 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 
<?php
/**
 * Represents a HTTP uploaded file
 * @package     IO
 * @subpackage  HTTP\upload
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Benoit SAUTEL <ben.popeye@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2016 10 28
 * @since       PHPBoost 3.0 - 2010 01 24
 * @contributor Julien BRISWALTER <j1.seth@phpboost.com>
 * @contributor Arnaud GENET <elenwii@phpboost.com>
*/

class UploadedFile
{
    private $name = '';
    private $mime_type = '';
    private $size = 0;
    private $tmp_name = '';

    public function __construct($name, $mime_type, $size, $tmp_name)
    {
        $this->name = $name;
        $this->mime_type = $mime_type;
        $this->size = $size;
        $this->tmp_name = $tmp_name;
    }

    public function get_name()
    {
        return $this->name;
    }

    public function get_name_without_extension()
    {
        $name = $this->get_name();
        return TextHelper::substr($name, 0, TextHelper::strpos($name, '.'));
    }

    public function get_extension()
    {
        $filename = $this->get_name();
        return TextHelper::strtolower(TextHelper::substr(TextHelper::strrchr($filename, '.'), 1));
    }

    public function get_mime_type()
    {
        return $this->mime_type;
    }

    public function get_size()
    {
        return $this->size;
    }

    public function get_temporary_filename()
    {
        return $this->tmp_name;
    }

    /**
     * Saves the uploaded file on the server's filesystem.
     * @param File $destination The destination file
     */
    public function save(File $destination)
    {
        move_uploaded_file($this->tmp_name, $destination->get_path());
    }
}
?>