I'm trying to figure out from a long time to print my file name in the MySQL database, file is uploading successfully into the path folder but unable to insert the file name into the database. below is my code
Choose file: <span class="text-danger">Max size 1mb, doc, pdf, jpg, jpeg, png & gif only</span>
<input type="file" name="fileToUpload" id="fileToUpload" required>
<input type="hidden" value="Upload Image" name="submit">
<?php
$target_dir = "../online/upload_files/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if file already exists
if (file_exists($target_file)) {
echo '<span style="color:#C0392B;text-align:center; size:45"> Sorry,
file already exists.</span>';
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 1048576) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType !=
"jpeg"
&& $imageFileType != "gif" && $imageFileType != "doc" && $imageFileType !=
"docx"
&& $imageFileType != "pdf"&& $imageFileType != "xlsx") {
echo '<span style="color:#C0392B;text-align:center;">Sorry, only JPG,
JPEG, PNG, doc, pdf & GIF files are allowed.</span>' ;
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo '<span style="color:#C0392B;text-align:center;">Sorry, your file
was not uploaded.</span>';
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
$target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has
been uploaded. & <b>Proposal Submited Successfully.</b>";
} else {
echo '<span style="color:#C0392B;text-align:center;"> Sorry, there
was an error uploading your file.</span>';
}
}
?>