I have a simplest php page for just uploading only MS Word or pdf files by a user. The function "move_uploaded_file" simply DOES not work. I have checked the limits in php.ini, checked with file and folder permissions in the target folder everything googled and verified, including to see if SELinux has any issues but it simply refuses to upload and neither is there any error seen as well. Frustrated now and nowhere replies related to EC2 instance are mentioning the solution online. Request experts to help and understand what is going wrong in the code presented below
Mine is a T2 large instance with PHP 7.2.11, Apache/2.4.37 (Red Hat Enterprise Linux), mysqld 8.0.17, still not understanding what is the issue, and no error is logged in error.log as well
<?php
include 'includes/UploadException.php';
define ('SITE_ROOT', realpath(dirname(__FILE__)));
echo "Current User:".get_current_user()."<br />";
if ($_POST['hdnOp'] == "A"){
$file = $_FILES['resume'];
$filename = $_FILES['resume']['name'];
$fileTmpName = $_FILES['resume']['tmp_name'];
$filesize = $_FILES['resume']['size'];
$fileerror = $FILES['resume']['error'];
$filetype = $_FILES['resume']['type'];
if ($filetype=="application/msword" || $filetype=="application/pdf"){
$random = rand(1111,9999);
$newfilename = $random.$filename;
$uploadpath = "/BMT/UserProfiles/".$newfilename;
echo "<h2>FILE = ".$newfilename."</h2>";
echo "<h2>ULPATH = ".$uploadpath."</h2>";
move_uploaded_file($fileTmpName,$uploadpath);
if ($_FILES['resume']['error'] === 0){
echo "<h3>ALL OK</h3>";
echo "ERROR CODE = ".$_FILES['resume']['error']."<br />";
echo "File Name :".$newfilename;
echo "File Size :".$filesize." kb";
echo "File Type :".$filetype;
} else {
throw new UploadException($_FILES['resume']['error']);
}
}
}
?>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=yes">
<!-- Bootstrap CSS -->
<!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<title>UPLOAD</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.4.1.min.js"></script>
<script type="text/javascript">
function submitForm(this){
return true;
}
</script>
</head>
<body class="container">
<table class='table table-bordered table-hover table-sm'><body>
<tr><td>
<form id="teacher-form" class="login-form" name="teacher-form" method="POST" enctype="multipart/form-data" action="test.php" onsubmit="return submitForm(this)">
<input type='hidden' name='hdnOp' value='A'>
<div id="form-content"></td></div><td></td></tr>
<tr><td>
<label>Upload Resume<b>*</b> <i>Note: Most recent upload will overwrite earlier version (if any)</i></label><br />
<input type="file" name="resume" id="resume" accept=".pdf,.docx,.doc,.rtf"><br /><div id='errresume'></div>
</td></tr>
<tr><td><input name="submit" type="submit" value="SUBMIT" /></td></tr>
</table>
</div>
</form>
</body>
</html>
I should be able to see the file in /BMT/UserProfiles/ folder
[root@ip-XXX-XX-XX-XXX bmt]# ls -al /BMT/UserProfiles/
total 4
drw-r--r--. 2 apache apache 24 Oct 16 12:17 .
drw-r--r--. 3 apache apache 26 Oct 16 12:05 ..