【发布时间】:2014-02-20 23:13:17
【问题描述】:
在我的 html 表单中,我有两个文件输入字段
<div style="width: 125px; height: 35px; float: left; font-weight: bold; font-size: 16px;">
Image Large
</div>
<div style="width: 125px; height: 35px; float: left; margin-top: 15px;">
<input type="file" name="large_image" id="large_image"/>
</div>
<div style="clear: both;"></div>
<div style="width: 125px; height: 35px; float: left; font-weight: bold; font-size: 16px;">
Image Small
</div>
<div style="width: 125px; height: 35px; float: left; margin-top: 15px;">
<input type="file" name="small_image" id="small_image"/>
</div>
在我的控制器文件中,我有两个函数可以上传小图像和大图像。这两个函数由一个函数执行,例如
private function insert_products() {
$this->upload_prodct_img_small();
$this->upload_prodct_img_large();
}
两个上传功能是这样的。
private function upload_prodct_img_large() {
$image_name = $this->get_image_name_uploade();
$config['upload_path'] = 'uploaded/large/';
$config['file_name'] = $image_name;
$config['overwrite'] = 'FALSE';
$config['allowed_types'] = 'png|PNG';
//$config['max_size'] = '1000';
//$config['max_width'] = '720';
//$config['max_height'] = '960';
$config['remove_spaces'] = TRUE;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('large_image')) {
$error = array('error' => $this->upload->display_errors());
$this->session->set_flashdata('error', $error);
} else {
$error = 'Successfully Uploaded';
$this->session->set_flashdata('error', $error);
}
}
private function upload_prodct_img_small() {
$image_name_small = $this->get_image_name_uploade();
$config['upload_path'] = 'uploaded/';
$config['file_name'] = $image_name_small ;
$config['overwrite'] = 'FALSE';
$config['allowed_types'] = 'png|PNG';
//$config['max_size'] = '1000';
//$config['max_width'] = '180';
//$config['max_height'] = '240';
$config['remove_spaces'] = TRUE;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('small_image')) {
$error = array('error' => $this->upload->display_errors());
$this->session->set_flashdata('error', $error);
} else {
$error = 'Successfully Uploaded';
$this->session->set_flashdata('error', $error);
}
}
在这两种情况下,我都将文件重命名为 $config 数组中的单个文件名。
问题是这样的。当我尝试上传两个文件时,只有“small_image”正在上传,而另一个文件总是丢失。
你可以看到我已经注释掉了宽度高度和尺寸。因为如果我不这样做,它会给我一个错误,说“您上传的文件超出了允许的高度或宽度”(类似的东西)。
我已经仔细检查了我上传的文件大小与允许的大小完全相同。
另一种情况是我做了这样的事情。
private function insert_products() {
//$this->upload_prodct_img_small();
$this->upload_prodct_img_large();
}
然后大图上传没有给出任何错误。
找不到我做错了什么?
【问题讨论】:
-
10 次浏览仍然没有回复 :(
-
你给 large_image 文件夹授权了吗?
-
是的,权限没有错误。因为当我尝试只上传大图像时,它正在上传而没有错误
-
最好只上传一个文件(大)并在编码中使用大图像创建小图像。
-
还是没有得到任何答案
标签: php html codeigniter file-upload