-1

Please see the given script for multiple file upload with error of undefined offset : 4 in your row

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);
M A SIDDIQUI
  • 2,028
  • 1
  • 19
  • 24
Faiq Ahmad
  • 13
  • 2
  • 3

1 Answers1

0

Change the following line:

for($i=0; $i<=count($_FILES['pics']); $i++) 

to

for($i=0; $i<count($_FILES['pics']); $i++)  // <= is replaced by <

and try again.

Explanation: As the indexes are from 0 to n-1 and count returns n value.

Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59