Php文件上传在xampp中工作,但不在Godaddy上

时间:2015-08-06 21:13:08

标签: php file-upload

我正在使用以下脚本,该脚本使用xampp在我的本地服务器上运行但不适用于godaddy。你能明白为什么会这样吗?

当使用不包含文件上传的类似表单时,表单成功发送到我的电子邮件收件箱时,我不会遇到任何问题。

<?php

//Email address and subject variables

$to = 'mike987689@outlook.com';
$subject = 'New Application'; 

//Form variables

$title = $_POST['title'];
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$middlename = $_POST['middlename'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$address3 = $_POST['address3'];
$town = $_POST['town'];
$postcode = $_POST['postcode'];
$dateofbirth = $_POST['dateofbirth'];
$gender = $_POST ['gender'];
$email = $_POST['email'];
$confirmemail = $_POST['confirmemail'];
$telephone = $_POST['telephone'];
$height = $_POST['height'];
$eyecolour = $_POST['eyecolour'];
$haircolour = $_POST['haircolour'];
$hairlength = $_POST['hairlength'];
$cosmetic = $_POST['cosmetic'];

//Message to be sent

$message = <<<EOD
Title: $title
First Name: $firstname
Surname: $surname
Middle Name(s): $middlename
Address Line 1: $address1
Address Line 2: $address2
Address Line 3: $address3
Town / City: $town
Postcode: $postcode
Date of Birth: $dateofbirth
Gender: $gender
Email: $email
Telephone: $telephone
Height: $height
Eye Colour: $eyecolour
Hair Colour: $haircolour
Hair Length: $hairlength
Cosmetics: $cosmetic
EOD;

/* GET File Variables */ 
$tmpName = $_FILES['attachment']['tmp_name']; 
$fileType = $_FILES['attachment']['type']; 
$fileName = $_FILES['attachment']['name']; 

/* Start of headers */ 
$headers = "From: $email"; 

if (file($tmpName)) { 
  /* Reading file ('rb' = read binary)  */
  $file = fopen($tmpName,'rb'); 
  $data = fread($file,filesize($tmpName)); 
  fclose($file); 

  /* a boundary string */
  $randomVal = md5(time()); 
  $mimeBoundary = "==Multipart_Boundary_x{$randomVal}x"; 

  /* Header for File Attachment */
  $headers .= "\nMIME-Version: 1.0\n"; 
  $headers .= "Content-Type: multipart/mixed;\n" ;
  $headers .= " boundary=\"{$mimeBoundary}\""; 

  /* Multipart Boundary above message */
  $message = "This is a multi-part message in MIME format.\n\n" . 
  "--{$mimeBoundary}\n" . 
  "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . 
  "Content-Transfer-Encoding: 7bit\n\n" . 
  $message . "\n\n"; 

  /* Encoding file data */
  $data = chunk_split(base64_encode($data)); 

  /* Adding attachment-file to message*/
  $message .= "--{$mimeBoundary}\n" . 
  "Content-Type: {$fileType};\n" . 
  " name=\"{$fileName}\"\n" . 
  "Content-Transfer-Encoding: base64\n\n" . 
  $data . "\n\n" . 
  "--{$mimeBoundary}--\n"; 
} 

/* Results rendered as html */

  $theResults = <<<EOD
<!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">
      <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
      <title>Reflex Media</title>

      <!-- Bootstrap -->
      <link href="css/bootstrap.min.css" rel="stylesheet">
      <link rel="stylesheet" href="mycss.css">
      <link rel='shortcut icon' type='image/x-icon' href='/favicon.ico'/>


      <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
      <!-- WARNING: Respond.js doesnt 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>

  <!-- NAVBAR
  ================================================== -->
    <body>
      <div class="navbar-wrapper">
          <div class="container">
            <nav class="navbar navbar-inverse navbar-static-top">
                <div class="container">

                  <div class="navbar-header">

                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>

                    <a class="navbar-brand" href="index.html">Alexa Media</a>
                  </div><!--navbar-header-->

                  <div id="navbar" class="navbar-collapse collapse">
                    <ul class="nav navbar-nav">
                        <li><a href="/">Home</a></li>
                        <li><a href="http://www.alexamedia.co.uk/about" title="about">About</a></li>
                        <li><a href="http://www.alexamedia.co.uk/contact" title="contact">Contact</a></li>
                        <li class="active"><a href="http://www.alexamedia.co.uk/apply" title="apply">Apply</a></li>
                    </ul>
                  </div><!--navbar-->
                </div><!--container-->
            </nav><!--nav-->
        </div><!--container-->
      </div><!--navbar-wrapper-->

      <div class="container-fluid" id="header-top">

        <div class="container">

          <h1>Thanks for your application!</h1>

          <h3>We will be in touch very soon.</h3>
      </div><!--container-->
      </div><!--header-top-->

      <!-- Marketing messaging and featurettes
      ================================================== -->
      <!-- Wrap the rest of the page in another container to center all the content. -->

      <div class="container" id="middle"> 

        <div id="faqs">
        </div>                    

          <!-- FOOTER -->
          <footer>
            <p class="pull-right"><a href="#">Back to top</a></p>
            <p>© 2015 Alexa Media</p>
          </footer>
      </div><!-- /.container -->

      <!-- Bootstrap core JavaScript
      ================================================== -->
      <!-- Placed at the end of the document so the pages load faster -->
      <script src="./files/jquery.min.js"></script>
      <script src="./files/bootstrap.min.js"></script>
      <!-- Just to make our placeholder images work. Dont actually copy the next line! -->
      <script src="./files/holder.js"></script>
      <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
      <script src="./files/ie10-viewport-bug-workaround.js"></script>


    <svg xmlns="http://www.w3.org/2000/svg" width="500" height="500" viewBox="0 0 500 500" preserveAspectRatio="none" style="visibility: hidden; position: absolute; top: -100%; left: -100%;">
      <defs></defs>

      <text x="0" y="23" style="font-weight:bold;font-size:23pt;font-family:Arial, Helvetica, Open Sans, sans-serif;dominant-baseline:middle">500x500
      </text>
    </svg>

    <div id="pAdId-80948329646">
      <script type="text/javascript" src="./files/ajs.php"></script>
    </div>
  </body>
</html>
EOD;

$flgchk = mail ("$to", "$subject", "$message", "$headers"); 

if($flgchk){
  echo "$theResults";
 }
else{
  echo "Error in Email sending";
}

?>

0 个答案:

没有答案