forked from devsbuz/landing-page-builder-Getleads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiupload.php
77 lines (41 loc) · 1.85 KB
/
iupload.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
<?php
$uploads_dir = 'elements/images/uploads';//specify the upload folder, make sure it's writable!
$relative_path = 'images/uploads';//specify the relative path from your elements to the upload folder
$allowed_types = array("image/jpeg", "image/gif", "image/png", "image/svg", "application/pdf");
/* DON'T CHANGE ANYTHING HERE!! */
$return = array();
//does the folder exist?
if( !file_exists( $uploads_dir ) ) {
$return['code'] = 0;
$return['response'] = "The specified upload location does not exist. Please provide a correct folder in /iupload.php";
die( json_encode( $return ) );
}
//is the folder writable?
if( !is_writable( $uploads_dir ) ) {
$return['code'] = 0;
$return['response'] = "The specified upload location is not writable. Please make sure the specified folder has the correct write permissions set for it.";
die( json_encode( $return ) );
}
if ( !isset($_FILES['imageFileField']['error']) || is_array($_FILES['imageFileField']['error']) ) {
$return['code'] = 0;
$return['response'] = "Something went wrong with the file upload; please refresh the page and try again.";
die( json_encode( $return ) );
}
$name = $_FILES['imageFileField']['name'];
$file_type = $_FILES['imageFileField']['type'];
if(in_array($file_type, $allowed_types)) {
if (move_uploaded_file( $_FILES['imageFileField']['tmp_name'], $uploads_dir."/".$name ) ) {
//echo "yes";
} else {
$return['code'] = 0;
$return['response'] = "The uploaded file couldn't be saved. Please make sure you have provided a correct upload folder and that the upload folder is writable.";
}
//print_r ($_FILES);
$return['code'] = 1;
$return['response'] = $relative_path."/".$name;
} else {
$return['code'] = 0;
$return['response'] = "File type not allowed";
}
echo json_encode( $return );
?>