You are on page 1of 4

php upload and download

How to Upload More Than One File using PHP


July 26, 2020

Source Code:
1) count(array_or_countable) :Count all elements in an array, or something in an object.
2) in_array — Checks if a value exists in an array
in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] ) : bool
needle = The searched value.
haystack = The array.
strict = If the third parameter strict is set to TRUE then the in_array() function will also
check the types of the needle in the haystack.
3) pathinfo(path) — Returns information about a file path
path = The path to be parsed.
options:
If present, specifies a specific element to be returned; one of PATHINFO_DIRNAME,
PATHINFO_BASENAME, PATHINFO_EXTENSION or PATHINFO_FILENAME.
4) move_uploaded_file — Moves an uploaded file to a new location
move_uploaded_file ( string $filename , string $destination ) : bool
filename = The filename of the uploaded file.
destination = The destination of the moved file.

FILEUPLOAD.PHP
<?php
if(isset($_POST['submit'])){
for($i = 0; $i< count($_FILES['file']['name']);$i++){
$name = $_FILES['file']['name'][$i];
$size = $_FILES['file']['size'][$i];
$type = $_FILES['file']['type'][$i];
$tmp = $_FILES['file']['tmp_name'][$i];

$max_size = 10000000; //10mb


$allowed = array('jpg','pdf','jpeg');
$location = "upload/".$name;

if($size > $max_size){


echo "$name too big to upload";
}
l if(!i ( hi f ($ PATHINFO EXTENSION) $ ll d)){
else if(!in_array(pathinfo($name,PATHINFO_EXTENSION),$allowed)){
echo "$name this type not allowed";
}
else{

move_uploaded_file($tmp,$location);
echo "<br>$name file Uploaded<br>";
}

?>

<html>
<head></head>
<body>
<table>
<tr>
<form action="" method="POST" enctype="multipart/form-data">
<td>
<input type="file" name="file[]" multiple >
</td>
<td>
<input type="submit" name="submit" value="SUBMIT">
</td>
</form>
</tr>
</table>
</body>
</html>

Blog 2

Enter your comment...


Popular posts from this blog

php Upload and Download File


July 09, 2020

Upload.php <!DOCTYPE html> <html lang="en"> <head>


<meta charset="UTF-8"> <title>upload</title> </head> <body> <?php $conn =
mysqli_connect('localhost','root','','example'); if(isset($_POST['submit'])){ $fileName =…

READ MORE

COMPLETE LOGIN SYSTEM IN PHP AND MYSQL


August 02, 2020

INDEX.PHP <?php session_start (); ? > <!


DOCTYPE html > < html lang = " en " > < head > < meta charset = "
UTF-8 " > < title >login system</ title > …
< link rel = " stylesheet " href

READ MORE

Powered by Blogger

Theme images by Michael Elkan

UNKNOWNBLOGGER

VISIT PROFILE

Archive
Labels

Report Abuse

You might also like