I am making an application form for users to apply for jobs and upload their CVs. The php code I made sends the file name to the DB so it is working correctly I guess.
Since I don't see any files after few tests. I tried to change the upload directory so when users upload their CVs it goes to the "uploads" folder in the root.
<?php
if(isset($_POST['uploadCV'])) {
$file = $_FILES['uploadCV'];
$fileName = $_FILES['uploadCV']['name'];
$fileTmpName = $_FILES['uploadCV']['tmp_name'];
$fileSize = $_FILES['uploadCV']['size'];
$fileError = $_FILES['uploadCV']['Error'];
$fileType = $_FILES['uploadCV']['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png', 'doc', 'docs', 'pdf');
if(in_array($fileActualExt, $allowed) ) {
if($fileError === 0) {
if($fileSize < 50000 ) {
$fileNameNew = uniqid('', true). '.' . $fileActualExt;
$fileDestination = 'uploads/' . $fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
echo "File uploaded!";
} else {
echo "File is too large...minimum size is 50MB";
}
} else {
echo "there was a error uploading your file, please ty again!";
}
} else {
echo "You can't upload this file type!";
}
}
As for the HTML:
<input type="file" name="uploadCV"/>
create-form.php:
<?php
header("Location: http://localhost/Rocket/includes/thankYou.php");
include('connection.php');
if(isset($_POST['addForm'])) {
$fullName = $_POST['fullName'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$dob = $_POST['dob'];
$degree = $_POST['degree'];
$expYears = $_POST['expYears'];
$position = $_POST['jobPosition'];
$whyHire = $_POST['whyHire'];
$uploadCV = $_POST['uploadCV'];
$dateApplied = $_POST['dateApplied'];
$db = new Database();
$db->connect();
$db->insert('users',array('fullName'=>$fullName,'email'=>$email, 'mobile'=>$mobile,
'dob'=>$dob, 'degree'=>$degree, 'expYears'=>$expYears, 'position'=>$position,
'whyHire'=>$whyHire, 'uploadCV'=>$uploadCV, 'dateApplied'=>$dateApplied)); // Table name, column names and respective values
$res = $db->getResult();
print_r($res);
if($res) {
echo "Sent to DB";
die();
} else {
echo "query error";
}
}
I am expecting the code to upload the selected file by the user to the "uploads" folder but sadly no luck and I don't understand why. but I have a feeling it is the way I wrote the upload directory might be wrong.