code:
<?php
if(isset($_POST['submit']))
{
if(isset($_FILES['img_url']['name']))
{
for($i=0; $i<count($_FILES['img_url']['name']); $i++)
{
$tmpFilePath = $_FILES['img_url']['tmp_name'][$i];
if ($tmpFilePath != "")
{
$path = "../images/hotel_images/";
$name = $_FILES['img_url']['name'][$i];
$size = $_FILES['img_url']['size'][$i];
list($txt, $ext) = explode(".", $name);
$file= time().substr(str_replace(" ", "_", $txt), 0);
$info = pathinfo($file);
$filename = $file.".".$ext;
$filepath_upload = $path.$filename;
$imageFileType = strtolower(pathinfo($filename,PATHINFO_EXTENSION));
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" )
{
$j2 = $i+1;
$msg = "<div class='alert alert-success'>Sorry, ".$j2." Image files Extension .".$ext." are not Uploaded & Other files Uploaded Successfully <br/>.</div>" ;
}
else if(move_uploaded_file($_FILES['img_url']['tmp_name'][$i], $filepath_upload))
{
$banner_image_source_file = $filepath_upload;
$banner_image_save_file = $filepath_upload;
list($width_orig, $height_orig) = getimagesize($banner_image_source_file);
$img_url_name.=$filename."|";
}
}
$filepath = rtrim($img_url_name, '|');
}
if(!empty($filepath))
{
$query = mysqli_query($con, "INSERT INTO `hotel`(`img_url`, `status`) VALUES ('".$filepath."')");
if($query)
{
$msg .= "<div class='alert alert-success'>Hotel Record Added Successfully</div>";
}
else
{
$msg = "<div class='alert alert-success'>Unbale to Add Hotel Record Please Try Again !!!</div>";
}
}
else
{
$msg = "<div class='alert alert-success'>Unable to Add Please Try Again !! </div>";
}
}
else
{
$msg = "<div class='alert alert-success'>Unable to Add Please Try Again !! </div>";
}
}
?>
<form action="" method="POST" enctype="multipart/form-data" id="add-hotel-form">
<div class="form-group col-md-12">
<label for="hotel">Upload Hotel Images</label>
<input type="file" class="form-control-file" id="upload_hotel_img1" name="img_url[]" multiple>
</div>
<div class="form-group col-md-12">
<label for="room">Upload Room Images</label>
<input type="file" class="form-control-file" id="upload_room_img1" name="img_url2[]" multiple>
</div>
<input type="submit" class="btn btn-primary" name="submit" value="Submit">
</form>
In the following code I have create a simple form where I have two input field type='file' where I am able to upload only first one i.e. <label for="hotel">Upload Hotel Images</label> and move into the folder successfully but I also want to upload and move second input field i.e. <label for="room">Upload Room Images</label>. I don't have any idea about this. So, How can I do this? Please help me.
Thank You
Your Room Image input is called img_url2, which you never interact with in code.
For best practice, move the bulk of your PHP code into a file upload function, then call it once with img_url $_FILE input, and once with img_url2.
Example:
<?php
error_reporting(E_ALL);
ini_set("display_errors", true);
ini_set("display_startup_errors", true);
function uploadFile($file, $path)
{
$img_url_name = "";
if(is_array($file) && isset($file['name']) && isset($file['tmp_name']) && isset($file['size']))
{
$tmpFilePath = isset($file['tmp_name'][0]) ? $file['tmp_name'][0] : "";
$name = isset($file['name'][0]) ? $file['name'][0] : "";
list($txt, $ext) = explode(".", $name);
$file = time().substr(str_replace(" ", "_", $txt), 0);
$filename = $file.".".$ext;
$filepath_upload = $path.$filename;
$imageFileType = strtolower(pathinfo($filename,PATHINFO_EXTENSION));
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" )
{
return "<div class='alert alert-success'>Sorry, ".$name." Image files Extension .".$ext." are not Uploaded & Other files Uploaded Successfully <br/>.</div>" ;
}
else if(move_uploaded_file($tmpFilePath, $filepath_upload))
{
$img_url_name .= $filename."|";
}
$filepath = rtrim($img_url_name, '|');
if(!empty($filepath))
{
if(!isset($con))
{
global $con;
}
$query = mysqli_query($con, "INSERT INTO `hotel`(`img_url`, `room_url`) VALUES ('".$filename."','".$filepath."')");
if($query)
{
return "<div class='alert alert-success'>Hotel Record Added Successfully</div>";
}
}
}
return "<div class='alert alert-success'>Unable to Add Please Try Again !! </div>";
}
if(isset($_POST['submit']))
{
if(isset($_FILES['img_url']['name']))
{
echo uploadFile($_FILES['img_url'], "../images/hotel_images/");
}
if(isset($_FILES['img_url2']['name']))
{
echo uploadFile($_FILES['img_url2'], "../images/room_img/");
}
}
?>
<form action="" method="POST" enctype="multipart/form-data" id="add-hotel-form">
<div class="form-group col-md-12">
<label for="hotel">Upload Hotel Images</label>
<input type="file" class="form-control-file" id="upload_hotel_img1" name="img_url" multiple>
</div>
<div class="form-group col-md-12">
<label for="room">Upload Room Images</label>
<input type="file" class="form-control-file" id="upload_room_img1" name="img_url2" multiple>
</div>
<input type="submit" class="btn btn-primary" name="submit" value="Submit">
</form>
I use FormData() to upload multiple images from multiple fields. Please take a look at this code:
<head>
<title>Example</title>
</head>
<body>
<form enctype="multipart/form-data" id="add-hotel-form">
<div class="form-group col-md-12">
<label for="hotel">Upload Hotel Images</label>
<input type="file" class="form-control-file" id="upload_hotel_img1" name="img_url" multiple>
</div>
<div class="form-group col-md-12">
<label for="room">Upload Room Images</label>
<input type="file" class="form-control-file" id="upload_room_img2" name="img_url2" multiple>
</div>
<input type="button" class="btn btn-primary" name="submit" value="Submit" onclick="myfunction();">
</form>
</body>
<script>
function myfunction(){
var form_data = new FormData();
var image = document.getElementById('upload_hotel_img1').files.length;
var images = document.getElementById('upload_room_img2').files.length;
for (var x = 0; x < image; x++) {
form_data.append("image", document.getElementById('upload_hotel_img1').files[x]);
}
for (var x = 0; x < images; x++) {
form_data.append("images[]", document.getElementById('upload_room_img2').files[x]);
}
}
</script>
We can retrieve these images in the backend using the follwing : $_FILES["image"]['name'] and $_FILES["images"]['name'] respectively.
Related
I am using contact.php for contact form. I added an attachment field for upload file/image, pdf, docx in contact form using . But i can not integrate php functions for file attachment. I am weak in php, but this is very important for me to add this in my contact form.
Please someone help me. My form code and php code are given below. Thanks in advance.
//** This is html markup
<form id="Frmgroupa" class="form-style" method="post" onsubmit="return validator4(this)" action="contact.php">
<div class="col-md-6">
<div class="form-group">
<label for="form_name">Name of Candidate *</label>
<input type="text" id="name" class="form-control" name="name" placeholder="Name" value="<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['name'] : '' ?>" placeholder="" required autofocus />
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="form_need">State</label>
<select id="State" class="form-control" name="State" placeholder="" required autofocus>
<option value="UTTAR PRADESH">UTTAR PRADESH</option>
</select>
</div>
</div>
<div class="col-md-6">
<p>Address Proof *</p>
<div class="custom-file mb-3">
<input type="file" class="custom-file-input" id="Address_Proof" name="filename" >
<label class="custom-file-label" for="customFile">Choose file</label>
</div>
</div>
<div class="col-md-6">
<p>Identity Proof *</p>
<div class="custom-file mb-3">
<input type="file" class="custom-file-input" id="Identity_Proof" name="filename">
<label class="custom-file-label" for="customFile">Choose file</label>
</div>
</div>
</div>
<input type="submit" class="btn btn-warning btn-3d" value="SUBMIT" id="submit-button" />
<?php unset($_SESSION['cf_returndata']); ?>
</form>
//* This is the contact.php code
<?php
$myemail = "amit.joshi98#gmail.com";
$subject = "file Upload";
/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "Enter your name");
$State = $_POST['State'];
/* If URL is not valid set $website to empty */
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
{
$website = 'http://google.com';
}
/* Let's prepare the message for the e-mail */
$message = "Hello!
Your contact form has been submitted by:
Name: $name
State: $State
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: thank-you.html');
exit();
/* Functions we used */
function check_input($data, $problem = '')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
First you need to write the following phrase in the form tag
enctype="multipart/form-data"
Like this ...
<form action="process.php" method="post" enctype="multipart/form-data">
and then in process.php file check submit and save file in your path
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
for limit file Type
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
for last check error and set message for user
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
you can Check if file already exists or Check file size
But i suggest you write an uploader function for the file and use it wherever you want.
In this example, photo file types were used that you can change according to your needs
Working on a small image gallery project in php and mysql. The project has two table. Album (albumId and albumName) and gallery(id, imageName, albumId, img_name). So, when user need to create a image gallery, they need to input all the information like title, album name, and image. I am able to do most of the part, the section I was stuck was with inserting the dropdown list, which in my case is album. Here is my add_photo.php
<!--Adding Post Area-->
<form action="add_photo_check.php" method="POST" enctype="multipart/form-data">
<?php
if(isset($_SESSION['message']))
{
echo $_SESSION['message'];
unset($_SESSION['message']);
}
?>
<!--Form for post-->
<div class="form-group">
<label for="posttitle">
<h5>Photo Title</h5>
</label>
<textarea name="imageName" class="form-control" placeholder="photo title.." ></textarea>
</div>
<div class="form-group">
<label for="album">Select Album</label>
<select class="form-control" name="albumId" id="album">
<option>Select Album</option>
<?php
$sql = "select * from album";
$res = mysqli_query($conn,$sql);
while($row=mysqli_fetch_assoc($res)){
echo"<option value=\"" .$row['albumId'] . "\" >" .$row['albumName']."</option>\n";
}
?>
</select>
</div>
<div class="form-group">
<label for="uploadimage">
<h5>Upload image</h5>
</label>
<div class="btn">
<input type="file" name="image">
</div>
</div>
<input type="submit" value="Publish" name="publish" class="btn btn-primary">
</form>
</div>
This is my function file add_photo_check.php
<?php
include "includes/header.php";
if(isset($_POST['publish']))
{
$title=$_POST['imageName'];
$title=mysqli_real_escape_string($conn,$imageName);
$title=htmlentities($imageName);
$id=$_POST['albumId'];
$id=mysqli_real_escape_string($conn,$albumId);
$id=htmlentities($albumId);
$uploadOk = 1;
$img_name = $_FILES['image']['name'];
$errorMessage = "";
if($img_name != "") {
$targetDir = "images/upload/";
$img_name = $targetDir . uniqid() . basename($img_name);
$imageFileType = pathinfo($img_name, PATHINFO_EXTENSION);
if(strtolower($imageFileType) != "jpeg" && strtolower($imageFileType) != "png" && strtolower($imageFileType) != "jpg") {
$_SESSION['message']="<div class='alert alert-danger'> Sorry, only jpeg, jpg and png files are allowed!</div>";
$uploadOk = 0;
}
if($_FILES['image']['size'] > 100000){
$_SESSION['message']="<div class='alert alert-danger'> Image is too big to upload!</div>";
header("Location: add_photo.php");
}
if($uploadOk) {
if(move_uploaded_file($_FILES['image']['tmp_name'], $img_name)) {
//image uploaded okay
}
$sql="insert into gallery (title, id, img_name) value('$imageName','$albumId', '$img_name')";
$res=mysqli_query($conn,$sql);
if($res)
{
$_SESSION['message']="<div class='alert alert-success'> Post Successfuly Published</div>";
header("Location: add_photo.php");
}
else
{
$_SESSION['message']="<div class='alert alert-danger'> Something went wrong!</div>";
header("Location: add_photo.php");
}
}
}
}
?>
Any help will be greatly appreciated. Thank you.
I am on Ubuntu. I am trying to take user file upload of small images. I checked the $_FILES it's filled with data. I tried to debug the move command but it doesnot echo anything.
if ($_SERVER['REQUEST_METHOD'] == 'POST' ){
//Now handle everything
if(isset($_POST["submit"])) {
print_r($_FILES);
//Store the image
if(!empty($_FILES['uploaded_file']))
{
$path = "/neel/public/img/";
$path = $path.basename($_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) {
echo 'Its working';
} else{
echo 'I am done!!!';
die();
}
}
createnewEvent($conn);
header('Location:/neel/index.php');
}
}
You can check if the file exists by checking its name.
if(!empty($_FILES['file']['name']))
Where file is the name of input field for file.
P. G above here is correct.
Instead of checking, if $_POST['submit']
You should check this:
if(isset($_FILES['uploaded_file']['name']))
Try this code it's a complete sign up form with PHP , Bootstrap
HTML
<div class="container">
<div class="row">
<br>
<h1 class="text-center">Create new account</h1>
<br>
<div class="col-lg-4 col-md-6 col-sm-12">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
<div class="form-group">
<input type="text" class="form-control form-control-lg" name="name" placeholder="Your Name">
</div>
<div class="form-group">
<input type="text" class="form-control form-control-lg" name="username" placeholder="Username">
</div>
<div class="form-group">
<input type="password" class="form-control form-control-lg" name="password" placeholder="Password">
</div>
<div class="form-group text-center">
<div class='file-input'>
<input type='file' name="profile-img">
<span class='button label' data-js-label>Choose your profile image</span>
</div>
</div>
<div class="form-group">
<input type="submit" class="btn btn-success form-control form-control-lg" name="signup" value="Signup">
</div>
</form>
</div>
</div>
</div>
PHP
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$errors;
if (empty($_POST['name'])) {
$errors[] = "Name field is empty";
}
if (empty($_POST['username'])) {
$errors[] = "Username field is empty";
}
if (empty($_POST['password'])) {
$errors[] = "Password field is empty";
}
if (empty($_FILES['profile-img'])) {
$errors[] = "You should upload profile image";
} else{
$img = $_FILES['profile-img'];
$ext = end(explode('.', $img['name']));
$allowed_extensions = array('jpg', 'jpeg', 'png', 'gif');
$max_size = 4; //MegaBytes
if (! in_array($ext, $allowed_extensions)) {
$errors[] = "Please , Choose a valid image";
}
$img_size = $img['size'] / 1000000; // By Megabyte
if ($img_size > $max_size) {
$errors[] = "This picture is so large";
}
}
if (!empty($errors)) {
echo '<div class="container">';
foreach ($errors as $error) {
echo '
<div class="alert alert-danger" role="alert">
' . $error . '
</div>
';
}
echo "</div>";
} else {
$username = filter_var(htmlentities(trim($_POST['username'])), FILTER_SANITIZE_STRING);
$name = filter_var(htmlentities(trim($_POST['name'])), FILTER_SANITIZE_STRING);
$password = sha1(filter_var(htmlentities(trim($_POST['password'])), FILTER_SANITIZE_STRING));
// Profile Picture :-
$imgname = uniqid(uniqid()) . #date("Y-m-d") . "." . $ext;
$target_bath = "uploads/imgs/";
$target_bath = $target_bath . basename($imgname);
$orginal_img = $img['tmp_name'];
if (move_uploaded_file($orginal_img, $target_bath)) {
$sql = "INSERT INTO users(name, username, password,profile_picture, r_d) VALUES ('$name', '$username', '$password', '$target_bath', NOW())";
$result = mysqli_query($conn, $sql);
header('location: ./login.php');
}
}
}
The script you've shown shown will only "not echo anything" if $_SERVER['REQUEST_METHOD'] is not "POST". Assuming your description of events is accurate, then the problem is in the form #halojoy has asked that you show here.
I do hope that you are not redirecting the script back to itself. Also you shouldn't attempt to do a redirect after an echo.
I have created an add file upload function and multiple file upload function.
Add function is working fine, but Edit function is not working.
After submitting the EDIT form, the OLD VALUES are not saved in the database.
The file is saved in some other folder.
Kindly help.
this is my code:controller file:
if(isset($_POST['additionalimage_exists']) && $_POST['additionalimage_exists'] != ''){
$temp_image = $_POST['additionalimage_exists'];
//echo $temp_image;die;
if(isset($_FILES['additional_images']['name']) && $_FILES['additional_images']['name'] != ""){
$errors= array();
$additional_eventimages = $_FILES['additional_images']['name'];
foreach($_FILES['additional_images']['name'] as $key => $tmpName) {
$additionalimages = $_FILES['additional_images']['name'][$key];
$file_type = $_FILES['additional_images']['type'][$key];
$file_size = $_FILES['additional_images']['size'][$key];
$file_tmp = $_FILES['additional_images']['tmp_name'][$key];
move_uploaded_file($file_tmp,"images/events/".$additionalimages);
}
}
else
{
$additional_eventimages = $temp_image;
}
}
view File:
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="additional-image">Additional Images</label>
<input type="file" class="form-control" name="additional_images[]" value="<?php echo $additional_images;?>" multiple="multiple">
<input type="hidden" name="additionalimage_exists" value="<?php echo $additional_images;?>" class="form-control-file" id="exampleInputFile" placeholder="Enter Image Text" aria-describedby="fileHelp">
<div>
<?php echo $additional_images;?>
</div>
</div>
</div>
</div>
Try with this code.
if(isset($_FILES['additional_images']['name']) && $_FILES['additional_images']['name'] != ""){
$errors= array();
$additional_eventimages = $_FILES['additional_images']['name'];
foreach($_FILES['additional_images']['name'] as $key => $tmpName) {
$additionalimages = $_FILES['additional_images']['name'][$key];
$file_type = $_FILES['additional_images']['type'][$key];
$file_size = $_FILES['additional_images']['size'][$key];
$file_tmp = $_FILES['additional_images']['tmp_name'][$key];
move_uploaded_file($file_tmp,"images/events/".$additionalimages);
} else if(isset($_POST['additionalimage_exists']) && $_POST['additionalimage_exists'] != ''){
$additional_eventimages = $_POST['additionalimage_exists'];
} else {
$additional_eventimages = "";
}
This question already has an answer here:
PHP file uploads doesnot read $_FILES['image'] [duplicate]
(1 answer)
Closed 7 years ago.
Hello I'm trying to create a form which includes an upload file input.
My form is sending data to my database while the file uploaded is stored in the img folder.
Now the form without the upload input works fine. The upload script without the form works fine too. But I can't manage to make them work together. I tried to include the "upload script" in my main form script but it didn't worked. I actually don't khow how this procedure should be done.
What I would like to do is that when I submit the form the data goes in the database and the upload file in my img folder. I think the problem comes somehow from the submit button.
Sorry for posting all my code but I think it's necessary to understand...
This is my addOutfit.php (which sends the data of my form to my database)
require("ajax/db.php");
$message = " ";
if ( $_POST ) {
if (!empty($_POST['type'])){
$title = htmlspecialchars($_POST['title']);
$description = htmlspecialchars($_POST['description']);
$brand = htmlspecialchars($_POST['brand']);
$material = htmlspecialchars($_POST['material']);
$type = htmlspecialchars($_POST['type']);
$color = htmlspecialchars($_POST['color']);
$sql = "INSERT INTO outfit (title, description, brand, material, type, color) VALUES('$title', '$description', '$brand', '$material', '$type', '$color')";
$statement = $pdo->prepare($sql);
$statement->execute(['title' => $title, 'description' => $description, 'brand' => $brand, 'material' => $material, 'type' => $type, 'color' => $color]);
$message = "The item has been added";
} else {
$message = "The type field is compulsory";
}
}
?>
<!--AddOutfit form-->
<div class="container-fluid" id="addOutfitForm" >
<div class="col-xs-12 col-md-10">
<form action ="addOutfit.php" method="post" novalidate>
<?php if ( $message ) { ?>
<h3 style="color: red;"><?=$message?></h3>
<?php } ?>
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" name="title">
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea class="form-control" rows="3" name="description"></textarea>
</div>
<div class="form-group">
<label for="type">Type</label>
<input type="text" class="form-control" name="type">
</div>
<div class="form-group">
<label for="brand">Brand</label>
<input type="text" class="form-control" name="brand">
</div>
<div class="form-group">
<label for="color">Color</label>
<input type="text" class="form-control" name="color">
</div>
<div class="form-group">
<label for="material">Material</label>
<input type="text" class="form-control" name="material">
</div>
<div class="form-group" action="upload.php" method="post" enctype="multipart/form-data">
<label for="fileToUpload">Picture</label>
<input type="file" name="fileToUpload" id="fileToUpload">
</div>
<button type="submit" class="btn btn-default" name="submit" value="Upload Image">Send</button>
</form>
</div>
This is my upload.php (my uploading documents script)
<?php
$target_dir = "img/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
Your approach is confusing a bit. You need to check if you have POST request to store the data inside db and check also if you have a file to upload it
if(isset($_POST)) {
// validate and insert the data into db
// if isset $_FILES["fileToUpload"] update the file
if(isset($_FILES) && isset($_FILES["fileToUpload"]['name'])) {
}
}
Also don't forget to add the enctype="multipart/form-data" attribute to the form
<form action ="addOutfit.php" enctype="multipart/form-data" method="post" novalidate>
I think that you just need to add the enctype="multipart/form-data" attribute to your <form> tag.
See http://www.w3schools.com/tags/att_form_enctype.asp
Submitting files only works when the form data is submitted as multipart.
Instead of
<div class="form-group" action="upload.php" method="post" enctype="multipart/form-data"> <label for="fileToUpload">Picture</label>
Have you tried:
<form action ="addOutfit.php" method="post" enctype="multipart/form-data" novalidate>