Search
 
SCRIPT & CODE EXAMPLE
 

PHP

upload multiple images in php

extract($_POST);
$error=array();
$extension=array("jpeg","jpg","png","gif");
foreach($_FILES["files"]["tmp_name"] as $key=>$tmp_name) {
    $file_name=$_FILES["files"]["name"][$key];
    $file_tmp=$_FILES["files"]["tmp_name"][$key];
    $ext=pathinfo($file_name,PATHINFO_EXTENSION);

    if(in_array($ext,$extension)) {
        if(!file_exists("photo_gallery/".$txtGalleryName."/".$file_name)) {
            move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"photo_gallery/".$txtGalleryName."/".$file_name);
        }
        else {
            $filename=basename($file_name,$ext);
            $newFileName=$filename.time().".".$ext;
            move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"photo_gallery/".$txtGalleryName."/".$newFileName);
        }
    }
    else {
        array_push($error,"$file_name, ");
    }
}
Comment

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/>';
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: Diferencia entre dias PHP - Con date_diff() 
Php :: arc cosine php 
Php :: laravel eloquent update multiple records 
Php :: laravel eloquent get all where in 
Php :: Calling itself a static function in php 
Php :: remove last 3 character from string php 
Php :: magento 1.9 get all product 
Php :: laravel get file to browser send 
Php :: laravel datatable render html 
Php :: PHP Ternary Operator With Elseif Example 
Php :: laravel where() method 
Php :: php get html with special characters 
Php :: Codeigniter 3 Pass anything in query string 
Php :: removing the last value of an array 
Php :: php check if day in month 
Php :: simple pagination in php 
Php :: laravel CORS config `allowed_origins` should be an array 
Php :: Get data from array (from an API) in Laravel 
Php :: php into javascript 
Php :: php require once 
Php :: laravel seeder with relationships 
Php :: git reset head 3 . how to back git init 
Php :: Regex to remove span tags using php [duplicate] codegrepper 
Php :: call satic blco in magento 2 
Php :: multiple ternary operator in php 
Php :: uft8 json php 
Php :: wp menu declaration 
Php :: validate file count with validate in laravel 
Php :: limit wordpress search to title 
Php :: eloquent multiple orwhere 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =