php - 代码点火器不允许上传视频文件
问题描述
<?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”
不知道怎么回事!!
解决方案
我想也许我不能使用相同的上传库实例,所以我在 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);
}
现在一切正常
推荐阅读
- c++ - 替换失败的模板特化
- javascript - 带有 Konva 画布的可缩放和可拖动容器
- angular - 由于依赖关系树错误,仅在 Angular 中创建工作区失败
- ios - collapse_key,apns-collapse-id 在通过 Firebase 推送消息时无法在 iOS 上运行
- github - 如何根据两个推送规则定义要运行的工作流
- entity-framework - 手动创建 Ef Core 迁移脚本
- batch-file - 在 Windows 上从批处理脚本运行 cmake 命令时如何将不同的目录引用到 cmake
- excel - 如果 B1 有文本,则在 A1 中输入今天日期的 Excel 公式
- sql-server - 当前元素之前的元素的 PERCENTILE_CONT - SQL Server
- html - 如何修复我的 CDN fontawesome 图标的圆形背景