如何检查mime类型并上传到不同的目录

时间:2015-01-30 15:30:40

标签: php codeigniter upload mime-types

private $uploadhost = "http://my.domain.com/";

function upload()
{
    date_default_timezone_set('Europe/Berlin');
    $key = "mykey";
    $redirect = "http://domain.com";
    $Date = date("Y-m-d_H-i-s");

    if ($_SERVER["REQUEST_URI"] == "/robot.txt") {
        die("User-agent: *\nDisallow: /");
    }

    if ($this->input->post('key')) {
        if ($this->input->post('key') == $key) {
            $target = getcwd() . "/r/" . basename($_FILES['file']['name']);
            if (move_uploaded_file($_FILES['file']['tmp_name'], $target)) {
                $filename = explode(".", $_FILES["file"]["name"]);
                $filename = $filename[sizeof($filename) - 1];
                rename($target, getcwd() . "/r/" . md5($Date) . "." . $filename);
                echo $this->uploadhost . "up/" . md5($Date) . "." . $filename;
            } else {
                echo "Something went wrong";
            }
        } else {
            header('Location: ' . $redirect);
        }
    } else {
        header('Location: ' . $redirect);
    }
}

您好,

我上面的脚本只适用于图片。我希望在上传后将其用于* .exe等文件进行下载。如何查看myme类型的文件并将文件上传到不同的目录。因此,图像将转至/ r,文件将转至/ d,而.txt将转至/ t。

我正在使用codeigniter 3 RC和ShareX。

1 个答案:

答案 0 :(得分:0)

请引导网址 https://www.codeigniter.com/user_guide/libraries/file_uploading.html在codeigniter中上传mime类型