dongmu1989 2019-04-24 23:58 采纳率: 0%
浏览 43

如何使用email字段和textarea字段修复文件上传

I'm doing a system for a particular region on our area that helps them to complain on their hometown. I'm having a hard time in this part where the output of my text fields and file upload must be on the same database.

here's my 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);
}

}

?>

and here's the form :

                        <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>

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度