File size: 3,365 Bytes
0ec97f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
 <?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['file_image'])) {
	require 'config/app.php';
	require 'config/upload.php';

	$options = array(
		'upload_path' => './uploads/images/', // set upload folder
		'thumb_path' => './uploads/thumb/', // set thumbnail folder
		'extension' => array('jpeg', 'jpg', 'png', 'gif', 'webp'), //allowed extension
		'mime_type' => array('image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/webp'), //allowed mime types
	);

	$upload = new hcgImageUploads($options);
	$upload->do_upload('file_image');
	$data = $upload->get_result();
}
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <title>PHP Image upload</title>
  </head>
  <body>


  	<div class="container-fluid p-5">

      <ul class="nav nav-pills">
        <li class="nav-item">
          <a class="nav-link" href="jquery-image-upload.php">JQuery Image upload</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="jquery-multiple-image-upload.php">JQuery multiple Images upload</a>
        </li>
        <li class="nav-item">
          <a class="nav-link active" href="index.php">Image upload</a>
        </li>
      </ul>

<br>

  		<div class="text-center"><h1>HTML form Image upload</h1></div>
  		<hr>

  		<div class="col-lg-5 mx-auto text-left">

  			<form action="" method="post" enctype="multipart/form-data">

  					<div class="form-group">
  						<label for="file_image">Select image </label>
  						<input type="file" class="form-control-file" name="file_image">
  					</div>

  					<div class="form-group">
  						<label for="img-title">Title (optional)</label>
  						<input type="text" class="form-control" name="title" id="img-title">
  					</div>

  					<button type="submit" class="btn btn-primary">upload</button>
  			</form>
<br>
  		</div>

      <?php
if (isset($data)) {
	if ($data['status'] == 'success') {
		echo '<div class="alert alert-success" role="alert">image upload successful</div>

            <div class="text-center"><img class="img-thumbnail" src="' . ($data['image_data']['thumb'] == "" ? $data['image_data']['url'] : $data['image_data']['thumb']) . '" alt="demo image"></div>

            <div class="card-body text-left">
              <pre>Name      : ' . $data['image_data']['name'] . '</pre>
              <pre>Type      : ' . $data['image_data']['type'] . '</pre>
              <pre>Size      : ' . $data['image_data']['size_format'] . '</pre>
              <pre>Size byte : ' . $data['image_data']['size'] . '</pre>
              <pre>Width     : ' . $data['image_data']['width'] . 'px</pre>
              <pre>Height    : ' . $data['image_data']['height'] . 'px</pre>
              <pre>thumb     : ' . $data['image_data']['thumb'] . '</pre>
              <pre>Link      : ' . $data['image_data']['url'] . '</pre>
            </div> ';
	} else {
		echo '<div class="alert alert-danger m-5" role="alert">
              ' . $data['msg'] . '
             </div>';
	}
}
?>



</div>

    <script>
    if ( window.history.replaceState ) {
        window.history.replaceState( null, null, window.location.href );
    }
</script>
  </body>
</html>