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?>
28<html>
29 <body>
30
31 <form action="" method="POST" enctype="multipart/form-data">
32 <input type="file" name="image" />
33 <input type="submit"/>
34 </form>
35
36 </body>
37</html>
1// Get the name of images
2 $Get_image_name = $_FILES['image']['name'];
3
4 // image Path
5 $image_Path = "images/".basename($Get_image_name);
6
7 $sql = "INSERT INTO student_table (imagename, contact) VALUES ('$Get_image_name', 'USA')";
8
9 // Run SQL query
10 mysqli_query($conn, $sql);
11
12 if (move_uploaded_file($_FILES['image']['tmp_name'], $image_Path)) {
13 echo "Your Image uploaded successfully";
14 }else{
15 echo "Not Insert Image";
16 }
17 }
1<?php
2$target_dir = "uploads/";
3$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
4$uploadOk = 1;
5$imageFileType =
6 strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
7
8// Check if image file is a actual image or fake image
9if(isset($_POST["submit"])) {
10 $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
11 if($check !== false) {
12 echo "File is an image - " . $check["mime"] . ".";
13
14 $uploadOk = 1;
15 } else {
16 echo "File is not an image.";
17
18 $uploadOk = 0;
19 }
20}
21
22// Check if file already exists
23if (file_exists($target_file)) {
24
25 echo "Sorry, file already exists.";
26 $uploadOk = 0;
27}
28
29
30 // Check file size
31if ($_FILES["fileToUpload"]["size"] > 500000) {
32 echo "Sorry, your file is too large.";
33 $uploadOk = 0;
34
35 }
36
37// Allow certain file formats
38if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
39&& $imageFileType != "gif" ) {
40 echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
41 $uploadOk = 0;
42}
43
44// Check if $uploadOk is set to 0 by an error
45if ($uploadOk == 0) {
46 echo "Sorry, your file was not uploaded.";
47// if everything is ok, try to upload file
48} else {
49
50 if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
51
52 echo "The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])).
53 " has been uploaded.";
54
55 } else {
56 echo "Sorry, there was an error uploading your file.";
57
58 }
59}
60?>