-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_upload.php
More file actions
52 lines (46 loc) · 1.38 KB
/
image_upload.php
File metadata and controls
52 lines (46 loc) · 1.38 KB
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
<?php
include_once 'core/core.inc.php';
if(isset($_FILES['image'])){
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
$extensions= array("jpeg","jpg","png");
if(in_array($file_ext, $extensions)=== false){
$error="extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size > '524288'){
$error='File size must be less then 512 kb';
}
if(empty($error)==true){
// move_uploaded_file($file_tmp, $source);
$base = "images/userdata/user";
$user_name = $_SESSION['user_id'];
$size = array(128, 64, 32);
$ext = ".jpg";
foreach ($size as $dimension) {
if ($file_ext == 'jpg' || $file_ext == 'jpeg') {
$img = imagecreatefromjpeg($file_tmp);
}elseif ($file_ext == 'png') {
$img = imagecreatefrompng($file_tmp);
}
$imgresize = imagescale($img, $dimension, $dimension);
imagejpeg($imgresize, $base.'_'.$user_name.'_'.$dimension.$ext);
imagedestroy($imgresize);
}
header("Location: index.php");
}else{
print_r($error);
}
}
?>
<html>
<body>
<form method="POST" action="image_upload.php" enctype="multipart/form-data">
<input type="file" name="image" />
<input type="submit"/>
</form>
</body>
</html>