代码点火器不允许上传视频文件

时间:2019-02-04 19:28:24

标签: php html codeigniter

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
include_once(APPPATH . "vuforiaApi/required/vuforiaclient.php");
class Main extends CI_Controller {

public function UploadImage()
{
    $Filename = time();
    $contentType;
    $contentUrl;
    if(isset($_FILES["ImageTarget"]["name"]))
    {

        $config['file_name'] = $Filename;
        $config['upload_path'] = './uploads/imagetargets';
        $config['allowed_types'] = 'jpg|gif|png|jpeg|JPG|PNG';
        $this->UploadFile($config,'ImageTarget',1);

    }
    else
    {
        echo 'Please select an Image to upload';
    }


    if(isset($_FILES["Content"]["name"]))
    {
        $contentType = $_POST["content_type"];
        if($_POST["content_type"]=="Video"){
        $configF['max_size'] = '0';
        $configF['upload_path'] = './uploads/content/videos';
        $configF['allowed_types'] = 'mp4|avi|mpg|mpeg|wmv';
        $configF['file_name'] = $Filename;
        $this->UploadFile($configF,'Content',2);
        $contentUrl = '/uploads/content/videos/'.$_FILES["Content"]["name"];
        }
        else if($_POST["content_type"]=="3D Asset"){
        $configF['upload_path'] = './uploads/content/assetbundles';
        $configF['file_name'] = $Filename;
        $configF['max_size'] = '0';
        $configF['allowed_types'] = 'unity3d';
        $this->UploadFile($configF,'Content',3);
        $contentUrl = '/uploads/content/assetbundles/'.$_FILES["Content"]["name"];
        }
        else
        {
            echo 'Please select content to upload';
        }

    }
}

public function sendTarget()
{
    //send target to vuforia site
}

public function UploadFile($cfg,$file,$filetype)
{
    $this->load->library('upload', $cfg);


    if ( ! $this->upload->do_upload($file))
    {
            $error = array('error' => $this->upload->display_errors());
            if($filetype == 1)
            echo "Image Target must be an image<br>";
            if($filetype == 2){
            print_r($error);
            print_r($this->upload->file_type);}
            if($filetype == 3)
            echo "Content must be an asset bundle<br>";
    }
    else
    {
            //$data = array('upload_data' => $this->upload->data());
            if($filetype == 2 || $filetype == 3)
            {
                //do something
            }
    }
}

}

当我尝试上传图像和视频文件时,图像已上传,但是我收到了视频文件(mp4,avi)的错误

Array ( [error] =>
The filetype you are attempting to upload is not allowed.
) 

mimes.php的条目正确

'mp4'   =>  'video/mp4',
'avi'   =>  array('video/x-msvideo', 'video/msvideo', 'video/avi', 
'application/x-troff-msvideo'),

$this->upload->file_type

给予

video/mp4

用于mp4

对于avi,它给出了     'video / x-msvideo'

我什至尝试在mp4和avi mime类型中添加“ application / octet-stream”

我不知道怎么了!

1 个答案:

答案 0 :(得分:0)

我想也许我不能使用相同的上传库实例,所以我在其中添加了一行代码     UploadFile($ cfg,$ file,$ filetype) 功能 完成所有操作后取消设置库

所以现在函数看起来像这样

    public function UploadFile($cfg,$file,$filetype)
{
    $this->load->library('upload', $cfg);

    if ( ! $this->upload->do_upload($file))
    {
            $error = array('error' => $this->upload->display_errors());
            if($filetype == 1)
            echo "Image Target must be an image<br>";
            if($filetype == 2){
            print_r($error);
            print_r($this->upload->file_type);}
            if($filetype == 3)
            echo "Content must be an asset bundle<br>";
    }
    else
    {
            //$data = array('upload_data' => $this->upload->data());
            if($filetype == 2 || $filetype == 3)
            {
                //do something
            }
    }
    unset($this->upload);
} 

现在一切正常