PHP脚本不上传文件

时间:2018-04-02 13:27:49

标签: php html file-upload fpdf

我有一个带有PHP表单的工作脚本,可以将文件上传到临时路径,但现在它无法正常工作?不知道我改变了什么?

其他所有工作,FPDF创建PDF并创建文件夹,但不会将3个文档上传到该文件夹​​。它工作,我编辑了一些文本,并添加了一些项目,但现在文件没有出现。我无法撤消我的代码。我经历过代码,但找不到任何导致此问题的错误。可能是我看不到的小东西。

以下是提交页面代码:

<link rel="shortcut icon" href="img/icon.ico" type="image/x-icon"/>
<?php
    include("php/dbconnect.php");
    $name=$_POST['name'];
    $email=$_POST['email'];
    $fax=$_POST['fax'];
    $privateaddress=$_POST['privateaddress'];
    $companyaddress=$_POST['companyaddress'];
    $econtactprivate=$_POST['contactprivate'];
    $contactcompany=$_POST['contactcompany'];
    $company=$_POST['company'];
    $wdd=$_POST['wdnd'];
    $seo=$_POST['seo'];
    $swd=$_POST['swd'];
    $fwd=$_POST['fwd'];
    $whs=$_POST['whs'];
    $ed=$_POST['ed'];
    $opi=$_POST['opi'];
    $dba=$_POST['dba'];
    $nd=$_POST['nd'];
    $cms=$_POST['cms'];
    $smo=$_POST['smo'];
    $dwd=$_POST['dwd'];
    $dr=$_POST['dr'];
    $wm=$_POST['wm'];
    $wta=$_POST['wta'];
    $ld=$_POST['ld'];
    $osc=$_POST['osc'];
    $other=$_POST['other'];
    $query=$_POST['query'];
    $pd=date('Y-m-d');
    $question1=$_POST['Q1'];
    $question2=$_POST['Q2'];
    $question3=$_POST['Q3'];
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>iBroker System</title>

<!-- BOOTSTRAP STYLES-->
<link href="css/bootstrap.css" rel="stylesheet" />
<!-- FONTAWESOME STYLES-->
<link href="css/font-awesome.css" rel="stylesheet" />
   <!--CUSTOM BASIC STYLES-->
<link href="css/basic.css" rel="stylesheet" />
<!--CUSTOM MAIN STYLES-->
<link href="css/custom.css" rel="stylesheet" />
<!-- GOOGLE FONTS-->
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />

<link href="css/ui.css" rel="stylesheet" />
<link href="css/datepicker.css" rel="stylesheet" /> 

<script src="js/jquery-1.10.2.js"></script>

<script type='text/javascript' src='js/jquery/jquery-ui-1.10.1.custom.min.js'></script>


</head>
<?php
include("php/header.php");
?>
    <div id="page-wrapper">
        <div id="page-inner">
            <div class="row">
                <div class="col-md-12">
                    <h1 class="page-head-line">Submit Claim</h1>
                    <h1 class="page-subhead-line">Please Enter Your Claim Information Below</h1>

                </div>
            </div>
            <script type="text/javascript" src="js/validation/jquery.validate.min.js"></script>
            <div class="row">

                <div class="col-sm-10 col-sm-offset-1">
           <div class="panel panel-primary">
                    <div class="panel-heading">
                    </div>
                    <form action="../submitclaim.php" method="post" id="signupForm1" class="form-horizontal">
                    <div class="panel-body">
                    <fieldset class="scheduler-border" >
                     <legend  class="scheduler-border">Claim Information: 
                     </legend>
                     <div class="form-group">
                            <label class="col-sm-2 control-label" 
                            for="Old">Name of The insured: 
                            </label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="name" name="name"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="Old">Email: </label>
                            <div class="col-sm-10">

                                <input type="text" class="form-control" id="email" name="email"/>
                            </div>
                            </div>

                                <div class="form-group">
                            <label class="col-sm-2 control-label" for="Old">Contact Number: </label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="contactprivate" name="contactprivate"/>
                            </div>
                        </div>

                                <div class="form-group">
                            <label class="col-sm-2 control-label" for="Old">Date Last Paid:: </label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="fax" name="fax"/>
                            </div>
                        </div>

                            <div class="form-group">
                            <label class="col-sm-2 control-label" for="Old">Date Of Loss: </label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="privateaddress" name="privateaddress"  />
                            </div>
                        </div>


                            <div class="form-group">
                            <label class="col-sm-2 control-label" for="Old">Time Of Loss: </label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="companyaddress" name="companyaddress"  />
                            </div>
                        </div>

                            <div class="form-group">
                            <label class="col-sm-2 control-label" for="Old">Name of Insurer </label>
                            <div class="col-sm-10">
                                <select  class="form-control" id="contactcompany" name="contactcompany" >
                                <option value="" >Select Insurer</option>
                                <?php
                                $sql = "select * from branch where delete_status='0' order by branch.branch asc";
                                $q = $conn->query($sql);

                                while($r = $q->fetch_assoc())
                                {
                                echo '<option value="'.$r['branch'].'"  '.(($branch==$r['id'])?'selected="selected"':'').'>'.$r['branch'].'</option>';
                                }
                                ?>                                  

                                </select>
                            </div>
                        </div>

                            <div class="form-group">
                            <label class="col-sm-2 control-label" for="Old">Claim Submission Type: </label>
                            <div class="col-sm-10">

                                <select name="wdnd">
                                <option value="">Select</option>
                                <option value="All Risk">All Risk</option>
                                <option value="Burglary">Burglary</option>
                                <option value="Electronic Equipment">Electronic Equipment</option>
                                <option value="FG">FG</option>
                                <option value="Fire">Fire</option>
                                <option value="Marine">Marine</option>
                                <option value="Money">Money</option>
                                <option value="Motor Medical Questionnaire">Motor Medical Questionnaire</option>
                                <option value="Motor Theft">Motor Theft</option>
                                <option value="Third Party">Third Party</option>
                                <option value="Personal Accident">Personal Accident</option>
                                <option value="Public Liability">Public Liability</option>
                                <option value="Windscreen">Windscreen</option>
                                <option value="Quote Estimate Agreement">Quote Estimate Agreement</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="Old">Was Insured There: </label>
                            <div class="col-sm-10">

                                <input type="text" class="form-control" id="Q1" name="Q1" />
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="Old">Cause Of Loss: </label>
                            <div class="col-sm-10">

                                <textarea class="form-control" rows="3" name="Q2" required></textarea>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="Old">Description Of Loss: </label>
                            <div class="col-sm-10">

                                <textarea class="form-control" rows="3" name="Q3" required></textarea>
                            </div>
                        </div>

                        <h3>Copy of Drivers License:</h3><input type=file name="files[]">
                        <h3>Copy of Public Permit:</h3><input type=file name="files[]">
                        <h3>Clearance Report:</h3><input type=file name="files[]">
                     <div class="panel-footer">

                                <input value="Submit" type="submit" name="submit" class="btn btn-primary pull-right">
                            </div>
                        </div>
                        </form>
             </div>
        <!-- /. PAGE INNER  -->
    </div>
    <!-- /. PAGE WRAPPER  -->
</div>
<!-- /. WRAPPER  -->

<div id="footer-sec">
   iBroker Finance System | Developed By Siyakha Technology</a>
</div>

<script src="js/jquery-1.10.2.js"></script> 
<!-- BOOTSTRAP SCRIPTS -->
<script src="js/bootstrap.js"></script>
<!-- METISMENU SCRIPTS -->
<script src="js/jquery.metisMenu.js"></script>
   <!-- CUSTOM SCRIPTS -->
<script src="js/custom1.js"></script>



</body>
</html>

这是提交php文件,用于处理PDF的创建和文档的上传:

<?php
    //set the question values
    $questions = array(
        'name' => "Name of the insured: ",
        'email' => "Email: ",
        'fax' => "Date last paid: ",
        'privateaddress' => "Date of Loss: ",
        'companyaddress' => "Time of Loss: ",
        'contactprivate' => "Contact Number: ",
        'contactcompany' => "Insurer: ",
        'Q1' => "Question 1: ",
        'Q2' => "Question 2: ",
        'Q3' => "Question 3: ",
        'category' => "Category: ",
    );
    //set the question answers
    $name          = $_POST['name'];
    $email         = $_POST['email'];
    $fax           = $_POST['fax'];
    $privateaddress= $_POST['privateaddress'];
    $companyaddress= $_POST['companyaddress'];
    $contactprivate= $_POST['contactprivate'];
    $contactcompany= $_POST['contactcompany'];
    $wdd= $_POST['wdnd'];
    $question1= $_POST['Q1'];
    $question2= $_POST['Q2'];
    $question3= $_POST['Q3'];
    //set the question names
    $Name  = $questions['name'];
    $Email  = $questions['email'];
    $Fax  = $questions['fax'];
    $Privateaddress  = $questions['privateaddress'];
    $Companyaddress  = $questions['companyaddress'];
    $Contactprivate  = $questions['contactprivate'];
    $Contactcompany  = $questions['contactcompany'];
    $WDD  = $questions['category'];
    $q1  = $questions['Q1'];
    $q2  = $questions['Q2'];
    $q3  = $questions['Q3'];

    require('fpdf.php');

    class PDF extends FPDF
    {
        // Page header
        function Header()
        {
            // Logo
            $this->Image('images/logo.png', 10, 6, 30);

            $this->SetFont('Arial', 'B', 15);

            $this->Cell(50);


            $this->Cell(90, 10, 'Claim Form', 'C');
            // Line break
            $this->Ln(20);
        }

        // Page footer
        function Footer()
        {

            $this->SetY(-15);

            $this->SetFont('Arial', 'I', 8);

            $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
        }
    }


    $pdf = new FPDF();
    $pdf->AddPage();
    $pdf->setFillColor(230,230,230);
    $pdf->SetFont('Arial', 'B', 10);
    //insert questions and answers
    $pdf->Image('logo.png',60,2,-300);
    $pdf->MultiCell(150, 16, sprintf("%s %s"));
    $pdf->Cell(0,10,'Contact No. (+268) 251 87193',0,0,'C');
    $pdf->MultiCell(150, 5, sprintf("%s %s"));
    $pdf->Cell(0,10,'Address : Office number 2, Matsapha M202, Swaziland',0,0,'C');
    $pdf->MultiCell(150, 5, sprintf("%s %s"));
    $pdf->Cell(0,10,'Email Address : info@minxinsurance.com',0,0,'C');
    $pdf->MultiCell(150, 5, sprintf("%s %s"));
    $pdf->Cell(0,10,'Website : www.minxinsurance.com',0,0,'C');

    $pdf->MultiCell(150, 10, sprintf("%s %s"));
    $pdf->Cell(0,10,'CLAIM FORM',0,0,'C',True);

    $pdf->MultiCell(150, 15, sprintf("%s %s"));

    $pdf->MultiCell(150, 7, sprintf("%s %s", $Name, $name));

    $pdf->MultiCell(150,7,sprintf("%s %s", $Email, $email));

    $pdf->MultiCell(150,7,sprintf("%s %s", $Fax, $fax));

    $pdf->MultiCell(150,7,sprintf("%s %s", $Privateaddress, $privateaddress));

    $pdf->MultiCell(150,7,sprintf("%s %s", $Contactprivate, $contactprivate));

    $pdf->MultiCell(150,7,sprintf("%s %s", $Companyaddress, $companyaddress));

    $pdf->MultiCell(150,7,sprintf("%s %s", $Contactcompany, $contactcompany));
    $pdf->MultiCell(150,7,sprintf("%s %s", $WDD, $wdd));

    $pdf->MultiCell(150,7,sprintf("%s %s", 'Was Insured There: ', $question1));

    $pdf->MultiCell(150,7,sprintf("%s %s", 'Cause of Loss: ', $question2));

    $pdf->MultiCell(150,7,sprintf("%s %s", 'Description of Loss: ', $question3));

    //display pdf

    mkdir("FileBrowser/files/$name", 0777);

    $total = count($_FILES['files']['name']);

    // Loop through each file
    for($i=0; $i<$total; $i++) {
        //Get the temp file path
        $tmpFilePath = $_FILES['files']['tmp_name'][$i];

        //Make sure we have a filepath
        if ($tmpFilePath != ""){
            //Setup our new file path
            $newFilePath = "FileBrowser/files/$name/" . $_FILES['files']['name'][$i];

            //Upload the file into the temp dir
            if(move_uploaded_file($tmpFilePath, $newFilePath)) {

              //Handle other code here

            }
        }
    }


    $filename = "FileBrowser/files/$name/$name.pdf";
    $pdf->Output($filename, 'F');

    require 'PHPMailer/PHPMailerAutoload.php';
    $mail = new PHPMailer;
    $mail->setFrom('iBroker@minxinsurance.com', 'iBroker Claims');
    $mail->addAddress('minxinsurance@realnet.co.za', 'Elsa');
    $mail->addAddress($email, $name);
    $mail->Subject  = 'New Claim Submitted';
    $mail->Body     = 'A New Claim for ' . $name . " has been submitted on iBroker";
    if(!$mail->send()) {

    } else {

    }
    header('Location: Finance/ClaimManage.php');

0 个答案:

没有答案