Codeigniter文件:
if (!empty($_FILES['left_full_image']['name']))
{
$uploaded_file_name = $_FILES['left_full_image']['name'];
$extension = pathinfo($uploaded_file_name, PATHINFO_EXTENSION);
$uploaded_file_name_withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $uploaded_file_name);
$filename = time().$uploaded_file_name_withoutExt;
$this->load->library('common');
$upload_sts = $this->common->global_file_upload($path, 'left_full_image', $filename);
if (isset($upload_sts['success']) && $upload_sts['success'] == 'y') {
if (isset($upload_sts['data']['full_path']) && file_exists($upload_sts['data']['full_path'])) {
$data['hd_left_full_image'] = $path.$filename.'.'.$extension;
}
}
}
if (!empty($_FILES['right_highlight_image']['name']))
{
$uploaded_file_name = $_FILES['right_highlight_image']['name'];
$extension = pathinfo($uploaded_file_name, PATHINFO_EXTENSION);
$uploaded_file_name_withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $uploaded_file_name);
$filename = time().$uploaded_file_name_withoutExt;
$this->load->library('common');
$upload_sts = $this->common->global_file_upload($path,'right_highlight_image',$filename);
if (isset($upload_sts['success']) && $upload_sts['success'] == 'y') {
if (isset($upload_sts['data']['full_path']) && file_exists($upload_sts['data']['full_path'])) {
$data['hd_right_highlight_image'] = $path.$filename.'.'.$extension;
}
}
}
当我尝试以同一形式上传文件时,文件都被上传,但第二个文件上传时,第一个上传文件的文件名不会被清除。
第二个文件也有同名的名字。
**第一档的名称:** 1500695786default_left ****
Array ( [success] => y [data] => Array ( **[file_name] => 1500695786default_left.jpg** [file_type] => image/jpeg [file_path] => /home/content/17/10326617/html/display/ci_ontime2/asset/upload/ [full_path] => /home/content/17/10326617/html/display/ci_ontime2/asset/upload/1500695786default_left.jpg [raw_name] => 1500695786default_left [orig_name] => 1500695786default_left.jpg [client_name] => default_left.jpg [file_ext] => .jpg [file_size] => 31.62 [is_image] => 1 [image_width] => 626 [image_height] => 626 [image_type] => jpeg [image_size_str] => width="626" height="626" ) )
**第二张图片名称:** 1500695786comingsoon1 ****
Array ( [success] => y [data] => Array ( **[file_name] => 1500695786default_left.png** [file_type] => image/png [file_path] => /home/content/17/10326617/html/display/ci_ontime2/asset/upload/ [full_path] => /home/content/17/10326617/html/display/ci_ontime2/asset/upload/1500695786default_left.png [raw_name] => 1500695786default_left [orig_name] => 1500695786default_left.png **[client_name] => comingsoon1.png** [file_ext] => .png [file_size] => 37.11 [is_image] => 1 [image_width] => 256 [image_height] => 256 [image_type] => png [image_size_str] => width="256" height="256" ) )
在我打印显示的第二个图像的名称时进行上传,显示为1500695786comingsoon1但是在上传图像后,如果我打印上传状态的结果,则显示第一个图像的名称,只有第二个图像具有的扩展名已被更改。但在第二个图像上传状态下,我可以在[client_name] =>中获取原始图像名称。 comingsoon1.png但不是文件名。
任何人都可以帮我解决实际出现的问题。
答案 0 :(得分:0)
除了那之外,你还会覆盖你的变量。我认为您的HTML只使用相同的字段名称。没有消息来源在这里猜测我们。
此外,您不需要'$ uploaded_file_name_withoutExt'。您可以这样做: basename ($ myfilename); http://php.net/manual/en/function.basename.php甚至您已经使用的 pathinfo 方法都可以返回没有扩展名的文件名。 http://php.net/manual/en/function.pathinfo.php。这里不需要正则表达式。
答案 1 :(得分:0)
您在两种情况下都使用相同的变量名$filename
。
替换
$filename = time().$uploaded_file_name_withoutExt;
到
$filename_firstImage = time().$uploaded_file_name_withoutExt;
使用不同的变量名称