1<?php error_reporting(0);
2
3$msg = "";
4
5if ( isset( $_POST['upload']) ) {
6
7 $filename = $_FILES["uploadfile"]["name"];
8 $tempname = $_FILES["uploadfile"]["tmp_name"];
9 $folder = $filename;
10
11 if ( move_uploaded_file( $tempname, $folder ) ) {
12 $msg = "Image uploaded successfully";
13 } else{
14 $msg = "Failed to upload image";
15 }
16}
17?>
18
19<!DOCTYPE html>
20<html>
21 <head>
22 <title>Image Upload</title>
23 </head>
24 <body>
25
26 <h2><?php echo $msg; ?></h2>
27 <form method="POST" action="" enctype="multipart/form-data">
28 <input type="file" name="uploadfile"/>
29 <button type="submit" name="upload">UPLOAD</button>
30 </form>
31 </body>
32</html>
1<?php
2 if(isset($_FILES['image'])){
3 $errors= array();
4 $file_name = $_FILES['image']['name'];
5 $file_size =$_FILES['image']['size'];
6 $file_tmp =$_FILES['image']['tmp_name'];
7 $file_type=$_FILES['image']['type'];
8 $file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
9
10 $extensions= array("jpeg","jpg","png");
11
12 if(in_array($file_ext,$extensions)=== false){
13 $errors[]="extension not allowed, please choose a JPEG or PNG file.";
14 }
15
16 if($file_size > 2097152){
17 $errors[]='File size must be excately 2 MB';
18 }
19
20 if(empty($errors)==true){
21 move_uploaded_file($file_tmp,"images/".$file_name);
22 echo "Success";
23 }else{
24 print_r($errors);
25 }
26 }
27?>