-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
44 lines (37 loc) · 1.24 KB
/
upload.php
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
<?php
if ($_SERVER ['REQUEST_METHOD'] == "POST") {
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'] ) ) );
$new_file_name=uniqid()."_post".".".$file_ext;
//echo $new_file_name;
$expensions = array (
"jpeg",
"jpg",
"png"
);
if (in_array ( $file_ext, $expensions ) === false) {
$errors [] = "extension not allowed, please choose a JPEG or PNG file.";
}
//echo "<script>alert(".$file_size.");</script>";
if ($file_size > 2097152) {
$errors [] = 'File size must be excately 2 MB';
}
if (count ( $errors ) === 0) {
$status=move_uploaded_file ( $file_tmp, "profiles/" . $new_file_name );
if (mysqli_query($conn, $sql)) {
//echo "<script>alert('Profile pic changed successfully!!');</script>";
} else {
//echo "<script>alert('Error uploading profile pic!!');</script>";
}
} else {
print_r ( $errors );
}
}
echo "<script>window.parent.setUploadName('".$_POST["mceUpload"]."','profiles/".$new_file_name."');</script>";
}
?>