0

I had a working script with a PHP form that would upload files to a temporary path but now its not working? no idea what i changed?

Everything else works, the FPDF creates the PDF and creates the folder but does not upload the 3 documents into that folder. it was working and i edited some text and added a few items but now the files do not appear. And i cannot undo my code. Iv gone through the code but cannot find anything wrong that is causing this. Probably something small that im not seeing.

Below is the submission page code:

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

And this is submission php file that handles the creating of the PDF and uploading of the documents:

<?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');
Yves Kipondo
  • 5,289
  • 1
  • 18
  • 31
Str1fe
  • 9
  • 1
  • 4
  • 2
    Haven't checked your PHP code, by my guess is that your troubles (at least partially) stem from the fact that you're missing `enctype="multipart/form-data"` in your HTML `
    ` tag.
    – Marijke Luttekes Apr 02 '18 at 13:30
  • You've posted a lot of code. Please do some debugging to narrow down your issue and remove all code that's not relevant. – M. Eriksson Apr 02 '18 at 13:31
  • @MarijkeLuttekes you were right!! Thank you!! Cant believe i missed that. I did redo the form layout and seems i forgot to put that back :D – Str1fe Apr 02 '18 at 14:03
  • @funkyfortyniner may i request the question be re-opened so i can mark Marijke as correct? – Str1fe Apr 02 '18 at 14:04
  • @Str1fe why? It's covered in the duplicate. – Funk Forty Niner Apr 03 '18 at 01:14
  • @FunkFortyNiner sorry sir just wanted to credit him :) I understand its in the duplicate thank you :) – Str1fe Apr 03 '18 at 01:16

0 Answers0