-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_to_facultyinfo.php
54 lines (49 loc) · 1.98 KB
/
upload_to_facultyinfo.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
<?php
require_once("connection.php");
require("functions.php");
$fileName = $_FILES["file"]["name"]; // The file name
$fileTmpLoc = $_FILES["file"]["tmp_name"]; // File in the PHP tmp folder
$fileType = $_FILES["file"]["type"]; // The type of file it is
$fileSize = $_FILES["file"]["size"]; // File size in bytes
$fileErrorMsg = $_FILES["file"]["error"]; // 0 for false... and 1 for true
$path=$_POST["path"];
$response = array('status' => true,'message'=>"" );
if ($conn->connect_error) {
$response['message']=$conn->connect_error;
$response['staus']=false;
die(json_encode($response));
}
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
$ext = end((explode(".", $fileName)));
$filename=generateRandomString(151);
$image=$path.$filename.".png";
$sql = "INSERT INTO facultyinfo(image,name,designation,description,type) VALUES ('".$image."','".$_POST["name"]."',' ".$_POST["designation"]."','".$_POST["description"]."','".$_POST["type"]."')";
if ($conn->query($sql) === TRUE) {
$response['message']="sqldone";
} else {
$response['message']=$sql."-".$conn->error;
$response['staus']=false;
die(json_encode($response));
}
$scratchpath="../images/scratch/".$filename.".".$ext;
if(move_uploaded_file($fileTmpLoc,$scratchpath)){
$response['message']="$fileName upload is complete";
} else {
$response['message']="move_uploaded_file function failed";
$response['staus']=false;
}
create_thumbnail($scratchpath,$image,180,180);
create_thumbnail($scratchpath,"../images/full/".$filename.".png",0,0);
create_thumbnail($scratchpath,"../images/medium/".$filename.".png",450,0);
create_thumbnail($scratchpath,"../images/thumb/".$filename.".png",180,180);
unlink($scratchpath);
echo json_encode($response);
?>