我想遍历多个文件上传并将其添加到我的json
这是我目前一次上传的内容:
$file_prefix = md5_file($tmp_file);
$file_name = $file_prefix . "_" . rand(1000, 99999) . "_{$session_check_data['id']}".".jpg";
$target_file = $vehicle_image_folder . "/".$file_name;
list($width, $height, $type, $attr) = getimagesize($tmp_file);
$image = new \Gumlet\ImageResize($tmp_file);
if($width > 1200) {
$image->resizeToWidth(1200);
}
$image->save($target_file, IMAGETYPE_JPEG);
if ($this->request->get('upload_thumb')) {
$thumbnail_file = $vehicle_image_folder . "/thumb_".$file_name;
$this->app['monolog']->info("thumbs required");
$image = new \Gumlet\ImageResize($target_file);
$image->resizeToWidth(400);
$image->save($thumbnail_file, IMAGETYPE_JPEG);
}
这是我试图做的事情
$files = array();
$l = 3;
foreach ($tmp_file as $k => $l) {
$file_prefix = md5_file($k);
foreach ($l as $i => $v) {
if (!array_key_exists($i, $files))
$files[$i] = array();
$files[$i][$k] = $v;
}
}
$counter = 1;
foreach ($files as $file) {
$count = $counter++;
$file_name = $file_prefix . "_" . rand(1000, 99999) . "_{$session_check_data['id']}".".jpg";
$target_file = $vehicle_image_folder . "/".$file_name;
list($width, $height, $type, $attr) = getimagesize($file);
$image = new \Gumlet\ImageResize($file);
if ($width > 1200) {
$image->resizeToWidth(1200);
}
$image->save($target_file, IMAGETYPE_JPEG);
if ($this->request->get('upload_thumb')) {
$thumbnail_file = $vehicle_image_folder . "/thumb_" . $file_name;
$this->app['monolog']->info("thumbs required");
$image = new \Gumlet\ImageResize($target_file);
$image->resizeToWidth(400);
$image->save($thumbnail_file, IMAGETYPE_JPEG);
}
}
然后我想在loc中的JSON中返回3个图像,也许是loc1,loc2,loc3?:
return $this->app->json(['success' => 1, 'info' => 'uploaded', 'loc' => $file_name]);
我希望能够显示已上传的3张图片