0% found this document useful (0 votes)
8 views1 page

Q Final

Uploaded by

genius_crystal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Q Final

Uploaded by

genius_crystal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

<?

php

// Count total files


$countfiles = count($_FILES['files']['name']);

// Upload directory
$upload_location = "uploads/";

// To store uploaded files path


$files_arr = array();

// Loop all files


for($index = 0;$index < $countfiles;$index++){

if(isset($_FILES['files']['name'][$index]) && $_FILES['files']['name']


[$index] != ''){

// File name
$filename = $_FILES['files']['name'][$index];

// Get extension
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));

// Valid image extension


$valid_ext = array("png","jpeg","jpg","docs","docx","xls","pdf");

// Check extension
if(in_array($ext, $valid_ext)){

// File path
$path = $upload_location.$filename;

// Upload file
if(move_uploaded_file($_FILES['files']['tmp_name'][$index],$path)){
$files_arr[] = $path;
}
}
}

echo json_encode($files_arr);
die;

You might also like