【问题标题】:PHP/HTML on Safari from Mac Os 10.6.5 works very slowlyMac Os 10.6.5 在 Safari 上的 PHP/HTML 运行缓慢
【发布时间】:2011-05-18 03:56:47
【问题描述】:

这是脚本:

<?php

require_once 'swift-mailer/lib/swift_required.php';

$name = $_POST['name'];
$email = $_POST['email'];
$form_subject = $_POST['form_subject'];
$form_message = $_POST['form_message'];

if (isset($_POST['submit'])) {

        if ($_POST['name'] != "") {
            $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
            if ($_POST['name'] == "") {
                $errors .= 'Please enter a valid name.<br/><br/>';
            }
        } else {
            $errors .= 'Please enter your name.<br/>';
        }

        if ($_POST['email'] != "") {
            $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
            if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                $errors .= "$email is <strong>NOT</strong> a valid email address.<br/><br/>";
            }
        } else {
            $errors .= 'Please enter your email address.<br/>';
        }

        if ($_POST['form_subject'] != "") {
            $form_subject = filter_var($_POST['form_subject'], FILTER_SANITIZE_STRING);
            if ($_POST['form_subject'] == "") {
                $errors .= 'Please enter a valid subject.<br/><br/>';
            }
        } else {
            $errors .= 'Please enter your subject.<br/>';
        }

        if ($_POST['form_message'] != "") {
            $form_message = filter_var($_POST['form_message'], FILTER_SANITIZE_STRING);
            if ($_POST['form_message'] == "") {
                $errors .= 'Please enter a valid comment.<br/><br/>';
            }
        } else {
            $errors .= 'Please enter your comment.<br/>';
        }


if (!$errors) {


//File upload

// Where the file is going to be placed 
$target_path = "uploads/";

// Add the original filename to our target path.  
//Result is "uploads/filename.extension" 
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);

if (is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) {

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename($_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}   
}
//End of file upload

//Create the Transport
$transport = Swift_MailTransport::newInstance();

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

//Create the message
$message = Swift_Message::newInstance();

  //Give the message a subject
$message->setSubject('New data submitted');

$ip=$_SERVER['REMOTE_ADDR'];
$date=date("l, F j, Y, g:i a");

  //Give it a body
$message->setBody("Here is the information submitted to 
www.polycysticliverdisease.com/html/contact_email.php 
from $ip on $date.\n\n
--------------------------------\n\n
name: $name \n\n
email address: $email \n\n
subject: $form_subject \n\n
comment: $form_message");

  //Add alternative parts with addPart()
//$message->addPart('My amazing body in plain text', 'text/plain');

//Create the attachment
// * Note that you can technically leave the content-type parameter out
$attachment = Swift_Attachment::fromPath($target_path);  

//Attach it to the message
$message->attach($attachment);

//Using setTo() to set all recipients in one go
$message->setTo(array('INFO@POLYCYSTICLIVERDISEASE.COM' => 'Diane Smith'));

//Set a From: address including a name
$message->setFrom(array('INFO@POLYCYSTICLIVERDISEASE.COM' => 'Contact Us'));

//Send the message
$numSent = $mailer->send($message);

//printf("Sent %d messages\n", $numSent);

if(isset($_FILES['uploadedfile'])){
$pathfile = "/home/vitusya/eximi.dreamhosters.com/Hawaii/html/uploads/" . $_FILES['uploadedfile']['name'];
@unlink($pathfile);
}

$to = "$email";
$subject = "Thank You!";
$body = "Thank you for e-mailing us.  We will reply as soon as possible.";
mail($to, $subject, $body);

        }


        else {
            echo '<div style="color: red">' . $errors . '<br/>
                </div>';



        }
    }



?> 

这是表格:

    <form name="contact" action="contact_email.php" method="POST" enctype="multipart/form-data">
        <table>
            <tr>
                <td>
                    <h2 class="lower">Contact Us</h2>
                </td>   
            </tr>
            <tr>
                <td class="pretty_border">
                    <label for="name">Your Name:</label><br />
                    <input class="text" type="text" name="name" />
                    <br />
                </td>   
            </tr>
            <tr>
                <td class="pretty_border">
                    <label for="email">Your E-Mail Address:</label><br />
                    <input class="text" type="text" name="email" />
                    <br />
                </td>   
            </tr>
            <tr>
                <td class="pretty_border">
                    <label for="form_subject">Subject:</label><br />
                    <input class="text" type="text" name="form_subject" />
                    <br />
                </td>   
            </tr>
            <tr>    
                <td class="textarea_border">
                    <label for="form_message">Your Message:</label><br />
                    <textarea rows="7" cols="50" name="form_message"></textarea>
                    <br />
                </td>   
            </tr>
            <tr>    
                <td>
                    <div class="fileinputs">
                        <input type="submit" class="file" name="submit" />
                        <div class="fakefile">
                                <img src="../assets/images/submit_btt.png" />
                        </div>
                    </div>
                    <div class="fileinputs">
                        <input type="file" class="file" name="uploadedfile" />
                        <div class="fakefile">
                                <img src="../assets/images/uf_btt.png" />
                        </div>
                    </div>
                    <div class="fileinputs">
                        <input type="reset" class="file" />
                        <div class="fakefile">
                                <img src="../assets/images/reset_btt.png" />
                        </div>
                    </div>
                    <div class="fileinputs">
                        <input type="button" class="file" onclick="window.print()" />
                        <div class="fakefile">
                                <img src="../assets/images/print_btt.png" />
                        </div>                      
                    </div>
                </td>   
            </tr>

        </table>
        </form>

在 Windows 上使用任何浏览器都可以正常工作,在 iPhone 和 iPad 上也可以正常工作。 看来问题出在Mac上。 该脚本执行非常缓慢,并从错误的电子邮件地址向用户发送“谢谢”信。 Mac 上的 Google Chrome 似乎也有同样的问题。

你认为它可能是什么?

谢谢!

【问题讨论】:

  • 您的意思是在您的 Mac 上运行的此脚本执行缓慢还是该页面在 Mac 10.6.5 上的 Safari 中无法正常工作?
  • 服务器是否在本地 Mac 上运行以用于开发目的?如果是,那将添加到可能的瓶颈列表中。如果不是,解决方案会更容易找到:-)
  • 只需使用 xdebug 并分析您的脚本。 (否则我的猜测是缓慢来自您使用 XHTML 语法但没有 XHTML mime 类型。)
  • 好吧,我猜它在 Mac 10.6.5 上的任何 Safari 上运行缓慢。我不这么认为
  • 我的客户去了一家 Apple 商店并在那里的几台电脑上进行了测试。

标签: php html macos google-chrome safari


【解决方案1】:

执行时间与浏览器无关 php是服务器端语言 您应该通过回显脚本中的各种变量来调试代码,并检查它们是否具有预期的值,如果没有,您可以查看回显变量以查找之前的代码可能出了什么问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-19
    • 2011-05-28
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多