This repository was archived by the owner on Nov 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathajaximage.php
More file actions
executable file
·61 lines (53 loc) · 2.03 KB
/
ajaximage.php
File metadata and controls
executable file
·61 lines (53 loc) · 2.03 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
53
54
55
56
57
58
59
60
61
<?php
include('db.php');
session_start();
$session_id='1'; //$session id
$path = "uploads/";
function getExtension($str)
{
$i = strrpos($str, ".");
if (!$i) {
return "";
}
$l = strlen($str) - $i;
$ext = substr($str, $i+1, $l);
return $ext;
}
$valid_formats = array("jpg", "png", "gif", "bmp","jpeg","PNG","JPG","JPEG","GIF","BMP");
if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
$name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];
if (strlen($name)) {
$ext = getExtension($name);
if (in_array($ext, $valid_formats)) {
if ($size<(1024*1024)) {
require_once('class.ImageFilter.php');
$filter = new ImageFilter;
$score = $filter->GetScore($_FILES['photoimg']['tmp_name']);
if (isset($score)) {
if ($score >= 40) {
echo "Image scored ".$score."%, It seems that you have uploaded a nude picture :-(";
} else {
//---------
$actual_image_name = time().".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
if (move_uploaded_file($tmp, $path.$actual_image_name)) {
mysqli_query($connection, "UPDATE users SET profile_image='$actual_image_name' WHERE uid='$session_id'");
echo "<img src='uploads/".$actual_image_name."' class='preview'>";
} else {
echo "Fail upload folder with read access.";
}
//--------
}
}
} else {
echo "Image file size max 1 MB";
}
} else {
echo "Invalid file format..";
}
} else {
echo "Please select image..!";
}
exit;
}