提交表单时iphone丢失网络连接

时间:2015-02-03 16:01:51

标签: php iphone forms

我有一个上传表格,详细说明和附件。

它在桌面上运行正常但是当我在我的iphone4和5上尝试上传时它只是说safari无法打开页面,因为网络连接丢失了......

我的表单将文档保存到文件夹,然后上传到MySQL数据库

任何想法?

Upload_portal.php:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>upload Portal</title>

    <!-- Bootstrap -->
     <link rel="stylesheet" type="text/css" href="css/bootstrap.css">

    <link rel="stylesheet" type="text/css" href="css/main.css">




    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
      <div class="row">
        <div class="col-sm-12">
            <img src="img/logo.jpg" />
        </div>
      </div><!-- END ROW -->
      <div class="row">
        <div class="col-sm-12 topBar">
            <h1>
              Premium Choice Upload portal
            </h1>
            <p>
              Welcome to the Premium Choice upload portal where you can securely send us all your documents. You can also request a copy of your documents
            </p>
        </div>
      </div><!-- END ROW -->
      <div class="clearfix"></div>
      <div class="container">
        <div class="row">
          <form action="upload.php" method="post" enctype="multipart/form-data">
          <div class="col-lg-6 col-md-6" style="font-size:1.2em;"><!-- THIS IS THE 1st section -->
            <div class="col-xs-12 sectionHeader">
              <h2> Section 1: Personal Details </h2>
            </div>
            <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 colClear">
              Select your type of policy:<strong style="color:red; font-size:1.2em;">*</strong>
            </div>
            <div class="col-lg-6  col-md-6 col-sm-6 col-xs-12 colClear">
              <select class="select" name="pol_type"> 
                <option selected="selected" value="Private Car">Private Car</option>
                <option value="Commercial Vehicle">Commercial Vehicle</option>
                <option value="Motorcycle">Motorcycle</option>   
              </select> 
            </div>
            <div class="col-xs-12" style="padding:0;">
                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 colClear">
                Customer reference <strong style="color:red; font-size:1.2em;">*</strong><br/>
                <input id="reference" type="text" name="reference" value="<?php echo $_GET['ref']; ?>"/>
                </div>
                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 colClear">
                    Email Address <strong style="color:red; font-size:1.2em;">*</strong><br/>
                  <input id="email" type="text" name="email"/>
                </div>
            </div>
            <?php
                                if(!empty($_SESSION['errors'][1])){
                                    $output =  "<div class='col-xs-12' style='color:red;'>";


                                    $output .= $_SESSION['errors'][1];


                                    $output .= "</div>";
                                    echo $output;
                                }
            ?>

            <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 colClear">
              First Name <strong style="color:red; font-size:1.2em;">*</strong><br/>
              <input id="firstName" type="text" name="first_name"/>
            </div>
            <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 colClear">
              last Name <strong style="color:red; font-size:1.2em;">*</strong><br/>
              <input id="lastName" type="text" style="float:right;" name="last_name"/>
            </div>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 colClear" style="padding:0;">
              <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                Vehicle registration <strong style="color:red; font-size:1.2em;">*</strong><br/>
                <input id="reg" type="text" name="registration"/>
              </div>
              <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                Contact Number <strong style="color:red; font-size:1.2em;">*</strong><br/>
                <input id="number" type="text" style="float:right;" name="number"/>
              </div>
            </div>

          </div>
          <div class="col-lg-6 col-md-6"><!-- THIS IS THE 2nd section -->
            <div class="col-xs-12 sectionHeader">
              <h2> Section 2: Send us your documents online</h2>
            </div>
            <div class="col-lg-12 text-center" style="font-size:0.9em;">
              <p class="colClear">Attach your scanned documents as JPG,PDF,DOC,TIF,PNG,GIF (Maximum 20MB)</p>
            </div>
            <div class="col-lg-10 col-sm-offset-2 uploadSection">
              <div class="col-xs-12 colClear">
                <input class="colClear" type="file" size="40" name="pictures[]" />

              </div>
              <div class="col-xs-12 colClear">
                <input class="colClear" type="file" size="40" name="pictures[]" />

              </div>
              <div class="col-xs-12 colClear">
                <input class="colClear" type="file" size="40" name="pictures[]" />

              </div>
              <div class="col-xs-12 colClear">
                <input class="colClear" type="file" size="40" name="pictures[]" />

              </div>
              <div class="col-xs-12 colClear">
                <input class="colClear" type="file" size="40" name="pictures[]" />

              </div>
            </div>

          </div>
        </div><!-- END OF ROW -->
        <div class="colClear"></div>
        <div class="colClear"></div>
        <div class="row">
          <div class="col-lg-6 col-md-6">
            <div class="col-lg-12 sectionHeader colClear">
              <h2> Section 3: Request a copy of your documents</h2>
            </div>
            <div class="col-lg-12 text-center" style="font-size:1em;">
              <p>Do you have any other queries or copy document requests?</p>
            </div>
            <div class="col-lg-12">
              <textarea name="comments">

              </textarea><br/><br/>
              <p class="text-center" style="font-size:0.75em;">We are unable to send any documents via email. If you have requested such items, these will follow via first</p>
            </div>
          </div>
          <div class="col-lg-6 col-md-6">
            <div class="col-lg-12 sectionHeader colClear">
              <h2 class="text-center"> Submit your request </h2>
            </div>
            <div class="col-lg-12 colClear">
              <input type="submit" class="button colClear" value="" />   
                <p style="font-size:0.75em;">
                    <strong>Please Note</strong><br>
                    Our office hours are 9am-8pm Mon-Fri & 9am-3pm Sat which means any requests submitted outside of these hours will be dealt with the next working day.<br/><br/>
                    Photographs taken with a low resolution camera are not acceptable and we may also ask you to send us the original proof in the post. 

                </p>
              </form>
            </div>
          </div>
        </div>
      </div>


    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

Upload.php(表单处理文件):

<?php
session_start();
$_SESSION['errors'] = array();
require_once("includes/db_connection.php");
require_once("includes/functions.php");
require_once("Mail.php");
require_once("Mail/mime.php");

    $errors = array();

    //Variables from $_POST
        $ref = mysql_prep($_POST['reference']);
        $type = mysql_prep($_POST['pol_type']);
        $first_name = mysql_prep($_POST['first_name']);
        $last_name = mysql_prep($_POST['last_name']);
        $reg = mysql_prep($_POST['registration']);
        $number = mysql_prep($_POST['number']);
        $email = mysql_prep($_POST['email']);    
        $comments = mysql_prep($_POST['comments']);
        $date = date("d/m/Y");
        $full_name = $first_name . " " . $last_name;
    //Validations:
        //1) There needs to be at least one upload
        $total_files = count(array_filter($_FILES['pictures']['name']));
        if($total_files < 1)
        {
            $_SESSION['errors'][0] = "No files have been uploaded!";
        }
        //2) Reference needs to be certain length
        if(strlen($ref) !== 8)
        {
            $_SESSION['errors'][1] = "client reference must be a number, and must be 8 digits long";
        }
        //3) All Fields need to be filled
        if($type == "" || $first_name == "" || $last_name == "" || $reg == "" || $number == "" || $email == "")
        {
            $_SESSION['errors'][2] = "All Fields must have a value!";
        }
        //3) Email must be valid
        if(!filter_var($email, FILTER_VALIDATE_EMAIL))
        {
            $_SESSION['errors'][4] = "Email must be valid";
        }   
        //4) Files size limit to 20MB
        $total_size = 0;
        foreach ($_FILES["pictures"]["size"] as $size) 
        {
            $total_size = $total_size + $size;  
        }        
            if($total_size > 1e+7)
            {
                $_SESSION['errors'][3] = "File size limit is 20MB, your files are too big!";
            }























// If there are no errors in the validation then continue with script
if(empty($_SESSION['errors']))
{

    //Calls the function to upload the files/details to database, (Requires post variables);
    //insert_upload($ref,$type,$first_name,$last_name,$reg,$number,$email,$comments,$connection);

    $img_count = 0;
    $img_name1 = "";
    $img_name2 = "";
    $img_name3 = "";
    $img_name4 = "";
    $img_name5 = "";
    $newimg_count = 0;
    $newimg_name1 = "";
    $newimg_name2 = "";
    $newimg_name3 = "";
    $newimg_name4 = "";
    $newimg_name5 = "";
            //Foreach files uplaoded place the file name into variable to go into table for later reference.
            foreach ($_FILES["pictures"]["name"] as $key => $Name) 
            {
                $img_count++;
                    if($img_count == 1)
                    {
                        $img_name1 = $_FILES["pictures"]["name"][$key];
                        if($img_name1 !== "")
                        {
                            $newimg_count++;
                            $newimg_name1 = $newimg_count . $img_name1;
                        }else
                        {
                            $newimg_name1 = $img_name1;
                        }   
                        echo $newimg_name1; 
                    }elseif($img_count == 2)
                    {
                        $img_name2 = $_FILES["pictures"]["name"][$key];
                        if($img_name2 !== "")
                        {
                            $newimg_count++;
                            $newimg_name2 = $newimg_count . $img_name2;
                        }else
                        {
                            $newimg_name2 = $img_name2;
                        }   
                        echo $newimg_name2; 
                    }elseif($img_count == 3)
                    {
                        $img_name3 = $_FILES["pictures"]["name"][$key];
                        if($img_name3 !== "")
                        {
                            $newimg_count++;
                            $newimg_name3 = $newimg_count . $img_name3;
                        }else
                        {
                            $newimg_name3 = $img_name3;
                        }   
                        echo $newimg_name3; 
                    }elseif($img_count == 4)
                    {
                        $img_name4 = $_FILES["pictures"]["name"][$key];
                        if($img_name4 !== "")
                        {
                            $newimg_count++;
                            $newimg_name4 = $newimg_count . $img_name4;
                        }else
                        {
                            $newimg_name4 = $img_name4;
                        }
                        echo $newimg_name4; 
                    }else
                    {
                        $img_name5 = $_FILES["pictures"]["name"][$key];
                        if($img_name5 !== "")
                        {
                            $newimg_count++;
                            $newimg_name5 = $newimg_count . $img_name5;
                        }else
                        {
                            $newimg_name5 = $img_name5;
                        }
                        echo $newimg_name5; 
                    } 
            }   
    $query =  "INSERT INTO ";
    $query .= "customers";  
    $query .= "(`reference`, `policy_type`, `first_name`, `last_name`, `registration`, `number`, `email`, `doc1`, `doc2`, `doc3`,`doc4`,`doc5`,`comments`,`date`) ";
    $query .= "VALUES ('{$ref}', '{$type}', '{$first_name}', '{$last_name}' , '{$reg}' , '{$number}' , '{$email}' , '{$newimg_name1}' , '{$newimg_name2}' , '{$newimg_name3}', '{$newimg_name4}', '{$newimg_name5}','{$comments}','{$date}')";
    $result = mysqli_query($connection, $query);
    $_SESSION['query'] = $query;



























    $target_dir = "docs/";

    //IF/ELSE the folder is already created...
        if(!file_exists($target_dir . $ref . "/"))
        {//Create folder named 1 inside the customer ref folder.
            mkdir($target_dir . $ref . "/" . "1" . "/", 0775, true);
            $count = 0;
        }else
        {//Create new folder inside customer ref folder 
            //count the amount of folders inside docs/$ref/
            $find_folders = glob($target_dir . $ref . "/" . "*",GLOB_ONLYDIR);
            $count = count($find_folders);
            //create new folder inside $ref/ using count+1 to make the folder increase by 1
                $new_folder = $count +1;
                mkdir($target_dir . $ref . "/" . $new_folder . "/", 0775, true);        
        }
                //IF count exists then the $target_file changes to the new folder...
                    if($count > 0)
                        {
                            $target_file = $target_dir . $ref . "/" . $new_folder . "/";  
                        }else
                        {//else use first directory
                            $target_file = $target_dir . $ref . "/" . "1" . "/";
                        }
    //Loop through files and place them into $target_file...
        $namecount = 0;
        foreach ($_FILES["pictures"]["name"] as $key => $Name) 
        {

                $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
                $name = $_FILES["pictures"]["name"][$key];
                if($name !== ""){
                    $namecount++;
                    $newname = $namecount . $name;
                }else{
                    $newname = $name;
                }
                echo $newname . "</br>";
                move_uploaded_file($tmp_name, $target_file . "$newname");

        }





$from = " Upload portal <upload-portal@premiumchoiceinsurance.co.uk>";
$to = "Matthew <matthew.smart@premiumchoice.co.uk>";
$subject = "Document Upload, Policy: 123456789";
$host = "ssl://secure.emailsrvr.com";
$port = "465";
$username = "upload-portal@premiumchoiceinsurance.co.uk";
$password = "C4r1n5ur4nc3";
$crlf = "\n";
$web_root = "http://test.premiumchoiceinsurance.co.uk.php54-3.dfw1-2.websitetestlink.com/";
$link1 = "<a href='" . $web_root . $target_file . $newimg_name1 . "'>{$img_name1}</a>";
$link2 = "<a href='" . $web_root . $target_file . $newimg_name2 . "'>{$img_name2}</a>";
$link3 = "<a href='" . $web_root . $target_file . $newimg_name3 . "'>{$img_name3}</a>";
$link4 = "<a href='" . $web_root . $target_file . $newimg_name4 . "'>{$img_name4}</a>";
$link5 = "<a href='" . $web_root . $target_file . $newimg_name5 . "'>{$img_name5}</a>";


$html = "
<html>
<head>

</head>
<body>
<div style='width:100%;height:500px;'>
    <p>This email was made from the Document Upload Portal</p>

    <table style='width:400px;'>
        <tr style='background-color:#FFFFCC; height:50px;'>
            <td style='text-align:center;'>
                Customer reference: 
            </td>
            <td style='text-align:center;'>
                {$ref}
            </td>
        </tr>
        <tr style='background-color:#CCCCB2; height:50px;'>
            <td style='text-align:center;'>
                Policy Type: 
            </td>
            <td style='text-align:center;'>
                {$type}
            </td>
        </tr>
        <tr style='background-color:#FFFFCC; height:50px;'>
            <td style='text-align:center;'>
                Vehicle Registration 
            </td>
            <td style='text-align:center;'>
                {$reg}
            </td>
        </tr>
        <tr style='background-color:#CCCCB2; height:50px;'>
            <td style='text-align:center;'>
                name: 
            </td>
            <td style='text-align:center;'>
                {$full_name}
            </td>
        </tr>
        <tr style='background-color:#FFFFCC; height:50px;'>
            <td style='text-align:center;'>
                telephone:
            </td>
            <td style='text-align:center;'>
                {$number}
            </td>
        </tr>
        <tr style='background-color:#CCCCB2; height:50px;'>
            <td style='text-align:center;'>
                Email:
            </td>
            <td style='text-align:center;'>
                {$email}
            </td>
        </tr>
        <tr style='background-color:#FFFFCC; height:50px;'>
            <td style='text-align:center;'>
                Attached Files:
            </td>
            <td style='text-align:center;'>
                {$link1}<br/>
                {$link2}<br/>
                {$link3}<br/>
                {$link4}<br/>
                {$link5}<br/>

            </td>
        </tr> 
    </table>
    <table style='width:400px;'>
        <tr style='background-color:#CCCCB2; height:50px;'>
            <td style='text-align:center;'>
                Comments:<br/><br/>
                {$comments}
            </td>
        </tr>
    </table>
</div>

</body>
</html>
";
$headers = array (
              'From' => $from,
              'To' => $to,
              'Subject' => $subject
          );

$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'port' => $port,
    'auth' => true,
    'username' => $username,
    'password' => $password,
    'MIME-Version' => 1,
    'Content-type' => 'text/html;charset=iso-8859-1'
    ));


        $mime = new Mail_mime($crlf);

        // Setting the body of the email

        $mime->setHTMLBody($html);

        $body = $mime->get();
        $headers = $mime->headers($headers);


$mail = $smtp->send($to, $headers, $body);




        echo '<script type="text/javascript">
           window.location = "http://test.premiumchoiceinsurance.co.uk.php54-3.dfw1-2.websitetestlink.com/thanks.php"
      </script>';

}else//if there are errors in validation then redirect to index and show them
{
    redirect_to('upload_portal.php?ref=' . $ref);
}//END OF empty session




?>

1 个答案:

答案 0 :(得分:0)

当将图像从iphone发布到nginx后面的服务器(即aws beanstalk)时,我得到了“Safari无法加载页面,因为网络连接已丢失”而且Chrome&#34;无法连接到互联网&# 34 ;.结果是client_max_body_size的图像大于1M nginx默认值。 (似乎在桌面上工作很奇怪。)我的解决方案是将参数值增加到更合适的值。

在beanstalk上,解决方案是在名为.ebextensions的分发文件的根目录下创建一个文件夹,并使用以下代码放置名为nginx.config的文件(仅限于以.config结尾): files: /etc/nginx/conf.d/proxy.conf: content: | client_max_body_size 50M;