图片上传无法在代码管理器中使用 [英] Image upload not working in codeignitor
本文介绍了图片上传无法在代码管理器中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建图片上传代码。这首先创建目录,然后将图像上传到它。
I create image upload code. this create directory first and then upload images to it.
在表单上传3张图片。
我的代码是:
$dir_path = 'assets/images/product_images/'.$model;
mkdir($dir_path, 0777);
$i = 1 ;
foreach ($image as $new_image)
{
$dir_path_up = 'assets/images/product_images/'.$model."/";
$filename = $_FILES["$new_image"]["name"];
$image_name = $dir_path_up .$filename . $i. ".jpg";
echo $image_name;
$i++;
}
die();
echo
assets/images/product_images/255_2555/1.jpg
assets/images/product_images/255_2555/2.jpg
assets/images/product_images/255_2555/3.jpg
但是这些图片没有上传到目录。我回应我创建的图像名称。它的alredy改名。
But that images are not getting uploade in to directory. I echo the image name which i created. Its alredy renamed. Then why images not getting uploade into directory.
推荐答案
为什么图片不能上传到目录
解决方案
使用多图片上传可以很好地完成
<?php
$j = 0; // Variable for indexing uploaded image.
$target_path = 'assets/images/product_images/' . $last_id . '/'; // Declaring Path for uploaded images.
for ( $i = 0; $i < count($_FILES['image']['name']); $i++ )
{
// Loop to get individual element from the array
$validextensions = array("jpeg", "jpg", "png"); // Extensions which are allowed.
$ext = explode('.', basename($_FILES['image']['name'][$i])); // Explode file name from dot(.)
$file_extension = end($ext); // Store extensions in the variable.
$target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext) - 1]; // Set the target path with a new name of image.
$j = $j + 1; // Increment the number of uploaded images according to the files in array.
if ( ($_FILES["image"]["size"][$i] < 100000000) // Approx. 100kb files can be uploaded.
&& in_array($file_extension, $validextensions)
)
{
move_uploaded_file($_FILES['image']['tmp_name'][$i], $target_path);
}
else
{
}
}
这篇关于图片上传无法在代码管理器中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文