This repository has been archived by the owner on Apr 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathajaxImageUpload.php
91 lines (69 loc) · 2.23 KB
/
ajaxImageUpload.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
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
<?php
$mypath = "uploads/pets/".$_POST['pid'];
if (!file_exists($mypath)) {
mkdir($mypath, 0777, true);
}
$image = $_POST['image'];
list($type, $image) = explode(';',$image);
list(, $image) = explode(',',$image);
$image = base64_decode($image);
$image_name = time().'.png';
file_put_contents("uploads/pets/".$_POST['pid']."/".$image_name, $image);
$newname = $mypath.'/'.$image_name;
echo $newname;
include($_SERVER['DOCUMENT_ROOT'].'/inc/model/model.php'); // MODEL FILE....
$Object = new Model();
$Object->profileImage($image_name, $_POST['pid']); // ASSIGN CLASS DATA TO OBJECT...
/*
if (!file_exists($mypath)) {
mkdir($mypath, 0777, true);
}
define ("MAX_SIZE","9000");
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","jpeg");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
foreach ($_FILES['photos']['name'] as $name => $value)
{
$filename = stripslashes($_FILES['photos']['name'][$name]);
$size= filesize($_FILES['photos']['tmp_name'][$name]);
//get the extension of the file in a lower case format
$ext = getExtension($filename);
$ext = strtolower($ext);
if(in_array($ext,$valid_formats))
{
if ($size < (MAX_SIZE*1024))
{
$image_name = time().$filename;
$newname = $mypath.'/'.$image_name;
if (move_uploaded_file($_FILES['photos']['tmp_name'][$name], $newname))
{
echo $newname;
include($_SERVER['DOCUMENT_ROOT'].'/inc/model/model.php'); // MODEL FILE....
$Object = new Model();
$Object->profileImage($image_name, $_POST['pid']); // ASSIGN CLASS DATA TO OBJECT...
}
else
{
echo '<script>alert("You have exceeded the size limit! so moving unsuccessful!"); </script>';
}
}
else
{
echo '<script>alert("You have exceeded the size limit!"); </script>';
}
}
else
{
echo '<script>alert("Unknown extension!"); </script>';
}
}
} */
?>