-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathParseAndSaveResume.php
103 lines (98 loc) · 3.31 KB
/
ParseAndSaveResume.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
92
93
94
95
96
97
98
99
100
101
102
103
<?php
require 'ProceduresToJson.php';
require 'DocxConversion.php';
include 'vendor/autoload.php';
$widgetJobs = new ProcedureToJson();
$widgetJobs->init();
if(empty($_SESSION['user']))
{
header("Location: index.php");
die("Redirecting to index.php");
}
$DBH = common::getInstance()->getDatabase();
$userid = $_SESSION['user']['id'];
$ds = DIRECTORY_SEPARATOR;
$storeFolder = 'uploads';
echo " 1. We are starting file upload";
if (!empty($_FILES))
{
$tempFile = $_FILES['file']['tmp_name'][0];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
echo " 2. Target Path: " . $targetPath;
$targetFile = $targetPath. $userid . "_" . $_FILES['file']['name'][0];
echo " 2. Target File: " . $targetFile;
$fileType = $_FILES['file']['type'][0];
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $targetFile);
echo "Mime: " . $mime . " ,FileType:" . $fileType;
if($mime == "application/msword" || $mime == "application/octet-stream" || $fileType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
{
try
{
move_uploaded_file($tempFile,$targetFile);
echo " Moved files";
$widgetDocConversion = new DocxConversion($targetFile);
echo " Got Target File:" . $targetFile;
$text = $widgetDocConversion->convertToText();
echo " Text:" . $text;
unlink($targetFile);
}
catch (Exception $e)
{
echo 'Insert/Truncate failed: ' . $e->getMessage();
}
}
else if($mime == "application/pdf" || $fileType == "application/pdf")
{
echo " Inside PDF file reader";
$message = '';
try
{
$content = '';
$content = file_get_contents($_FILES['file']['tmp_name'][0]);
echo " Inside get contents";
if ($content) {
$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseContent($content);
$pages = $pdf->getPages();
foreach ($pages as $page) {
$text = $text . $page->getText();
}
echo " Text:" . $text;
}
else
{
throw new Exception('Unable to retrieve content. Check if it is really a pdf file.');
}
} catch(Exception $e)
{
$message = $e->getMessage();
}
}
else
{
die ("Error reading resume");
}
$widgetJobs->insert_resume_for_user($text, $userid);
$splitresults = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', $text, -1, PREG_SPLIT_NO_EMPTY);
$splitresults = array_unique($splitresults);
$TruncateSkills="DELETE FROM usersskills WHERE userid =" . $userid. " AND sourceid = 2";
$numRows=$DBH->exec($TruncateSkills);
$STHGetSkillIdFromSkills = $DBH->prepare('SELECT id FROM skills WHERE name = :skillname');
$STHGetSkillIdFromSkills->bindParam(':skillname', $skillname);
$STHInsertUserSkillRelation = $DBH->prepare("INSERT INTO usersskills (userid, skillid, sourceid) values (:userid, :skillid, 2)");
$STHInsertUserSkillRelation->bindParam(':userid', $userid);
$STHInsertUserSkillRelation->bindParam(':skillid', $skillid);
foreach($splitresults as $splititem)
{
$skillname = $splititem;
$STHGetSkillIdFromSkills->execute();
$resultsGetSkillId = $STHGetSkillIdFromSkills->fetch();
$skillid = $resultsGetSkillId[0];
if(isset($skillid))
{
$STHInsertUserSkillRelation->execute();
}
}
}
?>