Я делаю систему для определенного региона в нашем районе, которая помогает им жаловаться на свой родной город.Мне трудно в этой части, где вывод моих текстовых полей и загрузка файла должны быть в одной базе данных.
вот мой upload.php
<?php
if(isset($_FILES['fileName'])){
$errors = array();
$file_name = $_FILES['fileName']['name'];
$file_size =$_FILES['fileName']['size'];
$file_tmp =$_FILES['fileName']['tmp_name'];
$file_type=$_FILES['fileName']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['fileName']['name'])));
$description = $_POST['description'];
$email = $_POST['email'];
if(isset($_POST['email'])){
$email = $_POST['email'];
}
if(isset($_POST['description'])){
$description = $_POST['description'];
}
$expensions= array("jpeg","jpg","png");
if(in_array($file_ext,$expensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size > 10000000){
$errors[]='10mb maximum file size';
}
// if there are no errors...
if (empty($errors)==true) {
// upload the file...
move_uploaded_file($file_tmp,"uploads/".$file_name);
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
// and create a new record in the database
mysql_connect($servername, $username, $password) or die ('MySQL Not found // Could Not Connect.');
mysql_select_db("test") or die(mysql_error()) ;
mysql_query("INSERT INTO complaint (email, description, fileName) VALUES ('$email', '$description', '$file_name')") ;
echo "Success";
}else{
print_r($errors);
}
}
?>
и вот форма:
<div class="col-12">
<div class="card">
<div class="card-body">
<h4 class="card-title">Complaint Form</h4>
<form class="forms-sample" action="upload.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" name="email">
</div>
<div class="form-group">
Complaint Details<br><textarea cols="40" rows="15" required="yes" name="description" id="description">
</textarea>
</form>
</div>
</div>
</div>