Insert With Folder Img

<?php

include_once("db.php");
$insertdata=new Databases();


if(isset($_POST['insert']))
{

    $name = $_POST['name'];
    $email = $_POST['email'];
    $num = $_POST['num'];
    $msg = $_POST['msg'];

$target_dir = "flimg/";
$target_file = $target_dir . basename($_FILES["fileName"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

    $check = getimagesize($_FILES["fileName"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }

// Check if file already exists
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
}
// Check file size
if ($_FILES["fileName"]["size"] > 500000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" && $imageFileType != "JPG" && $imageFileType != "PNG" && $imageFileType != "JPRG") {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["fileName"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["fileName"]["name"]). " has been uploaded.";
$sql=$insertdata->insert($name,$email,$num,$msg);
if (isset($_REQUEST['email']))  {

//Email information
$admin_email = "kistlakall@gmail.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['name'];
$comment = $_REQUEST['msg'];

//send email
mail($admin_email, "$subject", $comment, "From:" . $email);
}
    } else {
        echo "Sorry, there was an error uploading your Data and File.";
    }
  }
 
}

?>

<!DOCTYPE html>

<html>

    <head>

        <title> PHP INSERT DATA </title>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

    </head>

    <body>
        <form action="" method="post" enctype="multipart/form-data">

            Name <input type="text" name="name"><br><br>

            Email <input type="email" name="email"><br><br>

            Number <input type="text" name="num"><br><br>

            Message <input type="text" name="msg"><br><br>

            Upload <input type="file" name="fileName"><br><br>

            <input type="submit" name="insert" value="Add Data To Database">

        </form>

    </body>

</html>

0 comments:

Tweet Now !!

Recommend us on Google!