Unfortunately petty much every single line of your PHP code should be improved.
The reason for your error was that /public_hml/
was not an absolute file path so PHP was interpreting it as relative. and looking for <current directory>/public_html/resume/
which is almost certainly invalid.
I have fixed pretty much everything for you, below.
$uploadOk = false; // Always assume false until proven ok.
if(!empty($_FILES['resume'])) {
// Check errors
if($_FILES['resume']['error'] === 0){
$folder_dir = $_SERVER['DOCUMENT_ROOT']."/resume/"; // use absolute path.
// $base = basename($_FILES['resume']['name']); //worthless.
// $resumeFileType = pathinfo($base, PATHINFO_EXTENSION);
$finfo = new finfo();
$fileMimeType = $finfo->file($_FILES['resume']['tmp_name'], FILEINFO_MIME_TYPE);
if(strtolower($fileMimeType) !== 'applicaton/pdf'){
$_SESSION['uploadError'] = "Wrong Format. Only PDF Allowed";
header("Location: edit-profile.php");
exit();
}
$file = uniqid("",true) . ".PDF"; // make sure unique is unique.
$filename = $folder_dir .$file;
//if(file_exists($_FILES['resume']['tmp_name'])) {
// if($resumeFileType == "pdf") {//worthless.
if($_FILES['resume']['size'] > 500000) { // File size is less than 5MB
$_SESSION['uploadError'] = "Wrong Size. Max Size Allowed : 5MB";
header("Location: edit-profile.php");
exit();
}
move_uploaded_file($_FILES["resume"]["tmp_name"], $filename);
}
else {
//There were file upload errors. Handle here.
}
}
Source
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…