我尝试同时在CodeIgniter中上传视频和图片,但只上传了图片... 我的HTML:
<form method="post" enctype="multipart/form-data" action="{$BASE_URL}multimedia/save" >
<b>Image</b><br/>
<input type="file" name="userfile" id="userfile"><br><br/>
<b>Video</b><br/>
<input type="file" name="video" id="video"><br><br/>
<input type="submit" value="Save"></form>
我的控制器:
public function save()
{
$storage_image_path = 'path';
if ($_FILES["userfile"]["name"]) {
move_uploaded_file($_FILES["userfile"]["tmp_name"], 'path' . $_FILES["userfile"]["name"]);
$today_folders = date('Y') .'/'. date('m'). '/' ;
if ( !file_exists( $this->config->item("path") . 'big/' . $today_folders ) ){
$old_umask = umask(0);
mkdir( $this->config->item("path") . 'large/' . $today_folders, 0777, true );
umask($old_umask);
}
$filename = $_FILES["userfile"]["name"];
$filename2 = $filename;
$extension = end(explode(".", $filename));
$extcnt = strlen($extension) + 1;
$fn_count = strlen($filename) - $extcnt;
$replacename = substr($filename, 0, $fn_count);
$newfilename = $replacename . date("-d");
$newfilename = $newfilename . '.' . $extension;
$original_image = 'path' . $filename;
$dimensions = getimagesize($original_image);
$width = $dimensions[0];
$height = $dimensions[1];
if ($width >= $height) {
$parametru = $width / 70;
$height = round($height / $parametru);
$width = 700;
} else {
$parametru = $height / 300;
$width = round($width / $parametru);
$height = 300;
}
$config['image_library'] = 'gd2';
$config['source_image'] = $original_image;
$config['create_thumb'] = false;
$config['maintain_ratio'] = true;
$config['width'] = $width;
$config['height'] = $height;
$config['master_dim'] = 'width';
$config['new_image'] = $storage_image_path . '/big/' . $newfilename;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
if (!$this->image_lib->resize()) {
echo $this->image_lib->display_errors();
exit;
}
@unlink($original_image);
} else {
$newfilename = "no_photo.jpg";
$image = 0;
}
$this->db->query("
INSERT INTO videos (
image,
video)
VALUES (?, ?)",
array(
$image,
0)
);
//$this->tpl->display('multimedia/add.php');
}
使用此功能我上传图片,现在如何修改此方法上传和视频。请帮助我们 我明白这个:
if ($_FILES["userfile1"]["name"])
{
$filename_v = $_FILES["userfile1"]["name"];
$filenamev_2 = $filename;
$config['upload_path'] = 'videos/mp4/'.$filename_v;
$config['allowed_types'] = 'mov|mpeg|mp3|avi|mp4';
$this->load->library('upload', $config);
if (!$this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
}
else
{
$data = array('upload_data' => $this->upload->data());
}
}
我没有收到错误,但视频没有在指定路径中上传
答案 0 :(得分:0)
默认情况下,上传例程要求文件来自名为userfile的表单字段,表单必须是&#34;多部分类型:
如果您想设置自己的字段名称,只需将其值传递给do_upload函数:
$field_name = "some_field_name";
$this->upload->do_upload($field_name)
请在http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html
了解详情因此,在上面的视频文件上传方案中,应该有以下代码。
$this->upload->do_upload('video');