<?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»
Я даже пытался добавить 'application / octet-stream' в типы mp4 и avi mime
Я не знаю, что не так !!