How to Upload 4 images only using PHP -


how upload 4 images using php

this code .. code correct , can upload 4 images

but when upload 1 image .. error!

error this: undefined offset: 1 in c:\wamp\www\resize\uploader.php on line 10

undefined offset: 1 in c:\wamp\www\resize\uploader.php on line 24

undefined offset: 1 in c:\wamp\www\resize\uploader.php on line 25

undefined offset: 1 in c:\wamp\www\resize\uploader.php on line 26

undefined offset: 1 in c:\wamp\www\resize\uploader.php on line 27

undefined offset: 1 in c:\wamp\www\resize\uploader.php on line 28

<?php  if(isset($_post['submit']) , $_server['request_method'] == "post"){ //foreach ($_files['images']['name'] $loop => $name) { ( $loop = 0; $loop <= 1; $loop++ ) { $files_folder = 'p/'; // files folder  $formats = array("jpg", "jpg", "png", "png", "jpeg", "jpeg"); // allowed formats  $temp = explode(".", $_files["images"]["name"][$loop]); // temp name  $extension = end($temp); // ext  $file_size_megabyte = '5'; // set max file size  $calculation = 1048576 * $file_size_megabyte; // convert byte megabyte  $max_file_size = $calculation; // result after converted  $rename = substr(str_shuffle(str_repeat("abcdefghijklmnopqrstuvwxyz0123456789", 6)), 6, 6); // rename file  $uploaded = $files_folder.$rename.'.'.$extension; // uploaded file link  if ((($_files["images"]["type"][$loop] == "image/jpeg") || ($_files["images"]["type"][$loop] == "image/jpg") || ($_files["images"]["type"][$loop] == "image/pjpeg") || ($_files["images"]["type"][$loop] == "image/x-png") || ($_files["images"]["type"][$loop] == "image/png")) && ($_files["images"]["size"][$loop] <= $max_file_size) && in_array($extension, $formats)){ move_uploaded_file($_files["images"]["tmp_name"][$loop], $uploaded); echo $uploaded; }   }  }   ?> 

this solution.

the html form is:

<form action="" method="post" enctype="multipart/form-data"> <p>pictures: <input type="file" name="images[]" /> <input type="file" name="images[]" /> <input type="file" name="images[]" /> <input type="file" name="images[]" /> <input type="submit" value="send" /> </p> </form> 

the php code is:

<?php foreach ($_files["images"]["error"] $key => $error) {     if ($error == upload_err_ok) {         $tmp_name = $_files["images"]["tmp_name"][$key];         $name = $_files["images"]["name"][$key];         move_uploaded_file($tmp_name, "data/$name");     } } ?> 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -