我的提交按钮有问题:它无法正常工作。它似乎与我以前的表格一起工作。我也在使用Spry验证。这是一个带PHP的简单HTML。我看不出我的错误在哪里(我刚开始学习PHP)。我已经在互联网上浏览了论坛,但我无法找到问题的答案。我正在尝试通过电子邮件向我发送基本表单,并选择在同一表单中上传文件。问题来自表单格式还是PHP文件?这是我的代码:
这是位于<body><div id="content">...</div></body>
<p><form action="upload.php" name="form1" id="form1" method="post" enctype="multipart/form-data">
<fieldset><legend><em>Please fill this form</em></legend>
First Name: <span id="sprytextfield1">
<input type="text" name="firstname" id="firstname" required="required" />
<span class="textfieldRequiredMsg">Please enter your first name.</span></span><br/><br/>
Last Name: <span id="sprytextfield2">
<input type="text" name="lastname" id="lastname" />
<span class="textfieldRequiredMsg">Please enter your last name.</span></span><br/><br/>
Job Title: <span id="sprytextfield3">
<input type="text" name="title" id="title" />
<span class="textfieldRequiredMsg">Please enter your desired title.</span></span><br/><br/>
Address: <span id="sprytextfield4">
<input type="text" name="address" id="address" />
<span class="textfieldRequiredMsg">Please enter your address.</span></span><br/><br/>
Postal Code: <span id="sprytextfield5">
<input type="text" name="postal" id="postal" />
<span class="textfieldRequiredMsg">(i.e.: A0A 0A0)</span><span class="textfieldInvalidFormatMsg"></span></span><br/>
<br/>
City: <span id="sprytextfield6">
<input type="text" name="city" id="city" />
<span class="textfieldRequiredMsg">Please enter the name of your city.</span></span><br/><br/>
Province: <span id="spryselect1">
<select name="province" id="province">
<option value="ontario">Ontario</option>
<option value="quebec">Quebec</option>
<option value="britishcolumbia">British Columbia</option>
<option value="alberta">Alberta</option>
<option value="manitoba">Manitoba</option>
<option value="saskatchewan">Saskatchewan</option>
</select>
</span><br/><br/>
Phone Number: <span id="sprytextfield7">
<input name="phone" type="text" id="phone" maxlength="13" />
<span class="textfieldRequiredMsg">(i.e.: XXX-XXX-XXXX)</span><span class="textfieldInvalidFormatMsg">(i.e.: XXX-XXX-XXXX)</span></span><br/>
<br/>
<hr />
Additional information:<br />
<textarea name="comments" id="comments" cols="50" rows="5"></textarea>
<br/><br/>
<label for="file">Resume/CV (PDF or Word format only):</label>
<input type="hidden" name="max" value="100000"/>
<input type="file" name="file" id="file"/><br><br />
E-mail:
<span id="sprytextfield8">
<input type="text" name="email" id="email" />
<span class="textfieldRequiredMsg">Your e-mail address is required.</span><span class="textfieldInvalidFormatMsg">(i.e.: aaa@aaaa.com)</span></span><br/>
<br/>
<br/>
<input name="submit" type="submit" value="Send" />
<input type="reset" name="reset" value="Clear" />
</fieldset>
</form></p>
</div>
</div>
这是外部PHP(upload.php)文件,其位置与前一个HTML(相同的CSS和HTML正文)具有相同的括号类型括号:
<?php
$allowedExts = array("pdf", "doc");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "aaplication/doc"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$title=$_POST['title'];
$address=$_POST['address'];
$postal=$_POST['postal'];
$city=$_POST['city'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$comments=$_POST['comments'];
$province=$_POST['province'];
$date=gmdate("M d Y");
print"<p><b>$date</b></p>";
print"<p>Thank you $firstname $lastname! We will get back to you.</p>";
$to="someuser@gmail.com";
$subject="Candidate Resume";
$body="Date:$date \n Subject:$subject \n First Name:$firstname \n Last Name:$lastname \n Title:$title \n Address:$address \n City:$city \n Province:$province \n Postal Code:$postal \n Telephone:$phone \n Email:$email \n Additional Information:$comments \n\n";
mail($to,$subject,$body);
?>
答案 0 :(得分:0)
检查服务器上的PHP错误日志,看看是否可以获得有关失败原因的信息。在调试一些无效的代码时,这已经帮助了我很多次。
答案 1 :(得分:0)
您的脚本有效,只需将if语句中的filesize值增加到适合这些类型文件的内容即可。 ($ _FILES [“file”] [“size”]&lt; 500000)
你只允许19k。