CodeIgniter中视频和图像上传的区别
我可以从我的文件上传图像或视频。我已将映像的配置文件设置为:CodeIgniter中视频和图像上传的区别,codeigniter,codeigniter-2,Codeigniter,Codeigniter 2,我可以从我的文件上传图像或视频。我已将映像的配置文件设置为: $config['upload_path'] = './docs/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '200'; $config['max_width'] = '250'; $config['max_height'] = '250'; $
$config['upload_path'] = './docs/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '200';
$config['max_width'] = '250';
$config['max_height'] = '250';
$config['file_name'] = md5(rand().time());
$this -> load -> library('upload', $config);
但当我上传视频时,这个配置将无法工作,因为我需要能够上传更大的文件(视频)。提交后,是否有任何方法可以了解我上传的内容(img/视频),并在此基础上启用配置文件
视频的配置如下所示:
$configVideo['upload_path'] = './docs/';
$configVideo['max_size'] = '50240';
$configVideo['allowed_types'] = 'avi|flv|wmv|mp3|wma';
$configVideo['overwrite'] = FALSE;
$configVideo['remove_spaces'] = TRUE;
$video_name = $date.$_FILES['video']['name'];
$configVideo['file_name'] = $video_name;
$this->load->library('upload', $configVideo);
$this->upload->initialize($configVideo);
您可以使用$\u文件首先查找类型。 未经测试 或者,如果您对表单中的文件使用不同的名称,那么为什么不尝试 [已更新]
$config['upload_path'] = './docs/';
if (is_array($_FILES) && isset($_FILES['image']['name'])) {
// is an image
$config['upload_path'] = './docs/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '200';
$config['max_width'] = '250';
$config['max_height'] = '250';
$config['file_name'] = md5(rand().time());
} elseif (is_array($_FILES) && isset($_FILES['video']['name'])) {
// is a video
$config['max_size'] = '50240';
$config['allowed_types'] = 'avi|flv|wmv|mp3|wma';
$config['overwrite'] = FALSE;
$config['remove_spaces'] = TRUE;
$video_name = $date.$_FILES['video']['name'];
$config['file_name'] = $video_name;
}
$this->load->library('upload', $config);
$this->upload->initialize($config);
嗨,谢谢你的回复。我仍然停留在问题的看法,视频文件名是视频和图像文件名是图像。如何在控制器中获取它,然后设置配置。我还在学习。请帮帮我。再次感谢您的回复。我在第二个代码示例中添加了一些额外的位(请参阅更新)$这将使用正确的设置运行上载库。再次非常感谢。当我尝试使用echo$config['file_name']显示时;它抛出一个错误:消息:未定义索引:文件名。可能的错误是什么?您尝试在哪里回显文件名?我尝试在控制器本身中回显它。加载库之后,我对load->view行进行了注释,以便查看输出:(
$config['upload_path'] = './docs/';
if (is_array($_FILES) && isset($_FILES['image']['name'])) {
// is an image
$config['upload_path'] = './docs/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '200';
$config['max_width'] = '250';
$config['max_height'] = '250';
$config['file_name'] = md5(rand().time());
} elseif (is_array($_FILES) && isset($_FILES['video']['name'])) {
// is a video
$config['max_size'] = '50240';
$config['allowed_types'] = 'avi|flv|wmv|mp3|wma';
$config['overwrite'] = FALSE;
$config['remove_spaces'] = TRUE;
$video_name = $date.$_FILES['video']['name'];
$config['file_name'] = $video_name;
}
$this->load->library('upload', $config);
$this->upload->initialize($config);