0% found this document useful (0 votes)
13 views

Fileupload in PHP Useing DB

Uploaded by

dipti dongarde
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Fileupload in PHP Useing DB

Uploaded by

dipti dongarde
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

<?

php
include_once 'dbConfig.php';

$statusMsg = '';

if (isset($_POST["submit"])) {
$targetDir = "uploads/";
$fileName = basename($_FILES["fileToUpload"]["name"]);
$targetFilePath = $targetDir . $fileName;
$fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION);

// Allow certain file formats


$allowTypes = array('jpg', 'png', 'jpeg', 'gif');

if (in_array($fileType, $allowTypes)) {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
$targetFilePath)) {
$insert = $db->query("INSERT INTO images (file_name, uploaded_on)
VALUES ('" . $fileName . "', NOW())");
if ($insert) {
$statusMsg = "The file " . $fileName . " has been uploaded
successfully.";
} else {
$statusMsg = "File upload failed, please try again.";
}
} else {
$statusMsg = "Sorry, there was an error uploading your file.";
}
} else {
$statusMsg = 'Sorry, only JPG, JPEG, PNG, & GIF files are allowed to
upload.';
}
}

echo $statusMsg;
?>

You might also like