I want to check if a file has been selected for upload when submitting my edit record form. Currently it's not working as it's overwriting the current filepath with a blank record instead of doing nothing. I have tried searching other questions related to this but none of the answers help me.
if($_FILES['healthandsafetyupload']['name'] != "") {
//H&S Policy File Upload
if (count($_FILES['healthandsafetyupload']['name']) > 0) {
$hsInt = count($_FILES['healthandsafetyupload']['name']);
//Loop through each file
for ($i = 0; $i < count($_FILES['healthandsafetyupload']['name']); $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['healthandsafetyupload']['tmp_name'][$i];
//Make sure we have a filepath
if ($tmpFilePath != "") {
//save the filename
$shortname = $_FILES['healthandsafetyupload']['name'][$i];
$fileExt = get_extension($shortname);
//save the url and the file
$hasfilePath = "uploads/has_" . random_string(14) . "." . $fileExt;
//Upload the file into the temp dir
move_uploaded_file($tmpFilePath, $hasfilePath);
}
}
}
}
$sql1 = "UPDATE `subcontractor_qs` SET
healthandsafetyupload = '" . mysql_real_escape_string($hasfilePath) . "' WHERE subcon_id = $subcon_id";
$query1 = mysql_query($sql1) or die(mysql_error());