Answers for "upload multi image php"

PHP
2

php upload multiple files

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TEST</title>
</head>
<body>
    <form autocomplete="off" method="post" action="" enctype="multipart/form-data">
        <input id="file" name="file[]" type="file" multiple="multiple">
        <button name="submit" type="submit">Senden</button>
    </form>
</body>
</html>
<?php 
    if(isset($_POST['submit'])){

        for($i = 0; $i < count($_FILES['file']['name']);$i++){
          $f_maxsize = 41943040;
          $f_ext_allowed = array("stl", "STL", "jpeg", "png", "gif");

          $f_name_2 = str_replace(" ","_", htmlspecialchars($_FILES["file"]['name'][$i]));
          $f_size  =  $_FILES["file"]['size'][$i];
          $f_tmp   =  $_FILES["file"]['tmp_name'][$i];
          $f_error =  $_FILES["file"]['error'][$i];
          $f_ext = pathinfo($f_name_2, PATHINFO_EXTENSION);

          # Check the file for errors etc...

          move_uploaded_file($f_tmp, "to/upload/directory/" . $_FILES["file"]['name'][$i]);

        }
    }
?>
Posted by: Guest on September-03-2021
0

how to add multiple images in php

if (isset($_POST['submit'])) {
    $j = 0; //Variable for indexing uploaded image 

    $target_path = "uploads/"; //Declaring Path for uploaded images
    for ($i = 0; $i < count($_FILES['file']['name']); $i++) { //loop to get individual element from the array

        $validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed
        $ext = explode('.', basename($_FILES['file']['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["file"]["size"][$i] < 100000) //Approx. 100kb files can be uploaded.
            && in_array($file_extension, $validextensions)) {
            if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) { //if file moved to uploads folder
                echo $j.
                ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>';
            } else { //if file was not moved.
                echo $j.
                ').<span id="error">please try again!.</span><br/><br/>';
            }
        } else { //if file size and file type was incorrect.
            echo $j.
            ').<span id="error">***Invalid file Size or Type***</span><br/><br/>';
        }
    }
}
Posted by: Guest on September-22-2021

Browse Popular Code Answers by Language