请参阅给定的脚本以获取多个文件上传,错误为未定义的偏移量:行中的4
for($i=0; $i<=count($_FILES['pics']); $i++) {
$tmpFilePath = $_FILES['pics']['tmp_name'][$i]; // this row error
$extract=explode(".",$_FILES["pics"]["name"][$i]);
$exten=$extract[1];
$completes=str_shuffle(str_replace(" ","",$_POST["title"].$extract[0])).".".$exten;
$images[]=$completes;
$newFilePath = "data/product/" . $completes;
move_uploaded_file($tmpFilePath, $newFilePath);
$data = getimagesize($newFilePath);
$width=$data[0];
$height = $data[1];
$newWidth= $width/$height*342;
$image = new SimpleImage();
$image->load($newFilePath);
$image->resize($newWidth,342);
$image->save("data/product/".$completes);
}
$images=implode(",",$images);
答案 0 :(得分:0)
更改以下行:
for($i=0; $i<=count($_FILES['pics']); $i++)
到
for($i=0; $i<count($_FILES['pics']); $i++) // <= is replaced by <
再试一次。
说明:由于索引从0
到n-1
,而计数返回n
值。