【问题标题】:Uploaded multiple photos but was only able to receive one上传了多张照片,但只能收到一张
【发布时间】:2018-07-28 16:30:40
【问题描述】:

大家好,当我转到联系人 php 表单时,我正在尝试查看是否可以一次从我的联系人 php 表单接收多张照片到我的雷鸟电子邮件我单击选择文件并突出显示要发送的照片将显示已选择的 13 张照片,然后我提交了包含这些照片的表格,然后我检查了我的雷鸟电子邮件,我只收到了一张照片。我附上了我的联系表格的 2 个屏幕截图,其中包含选择的 13 张照片和我收到的带有一张照片附件的电子邮件,而且我已经包含了联系表格中的 php 代码任何想法,因为这可能是什么问题任何帮助和解决方案都非常重要非常感谢提前感谢。

submitted form

received email

<?PHP
/*
Contact Form from HTML Form Guide
This program is free software published under the
terms of the GNU Lesser General Public License.
See this page for more info:
http://www.html-form-guide.com/contact-form/contact-form-attachment.html
*/
require_once("./include/fgcontactform.php");

$formproc = new FGContactForm();

//1. Add your email address here.
//You can add more than one receipients.

$to = $formproc->AddRecipient('test@alphaboss.ca'); //<<---Put your email 
address here
$subject = 'Form was submitted';
$message = 'New message from a visitor';
$headers = 'From: test@alphaboss.ca' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers); // 'test@alphaboss.ca', 'Form was 
submitted', 'New message from a visitor'

//2. For better security. Get a random tring from this link: 
// and put it here
$formproc->SetFormRandomKey('HG9hPBpn9Bn26yg');

$formproc->AddFileUploadField('photo','jpg,jpeg,gif,png,bmp',2024);
if(isset($_FILES ['name']))
if(isset($_FILES ['photo']))
if(count($_FILES['name']['photo'])) {
foreach ($_FILES['name']['photo'] as $file) {
 // Count total files 
$formproc = count($_FILES['photo']['name']);
} 
// Looping all files 
for($i=0;$i<$fromproc;$i++){ $file = $_FILES['photo']['name'][$i];
} 
// Upload file 
move_uploaded_file($_FILES['photo']['tmp_name'][$i],'submit/'.$file);   
    //do your upload stuff here
    echo $file;

}
}
if(isset($_POST['submitted']))
{
if($formproc->ProcessForm())
{
    $formproc->RedirectToURL("thank-you.php");
}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
 <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
 <title>Alpha Boss Computer Services</title>
<style>
body {font-family: Verdana, sans-serif;
margin: 0;
}
h1 {text-align:center;
color: navy;
}
#background-image {
background-image: url(alpha.png);
width: 100%;
top: 0;
left: 0;
height:100%; 
opacity: 0.2;
position: absolute;
background-repeat: repeat;
padding: 0;
margin: 0;
z-index:0;
}
 .navbar {
  overflow: hidden;
  background-color: #333;
  position: fixed;
  bottom: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  }

 .navbar a {
  display: inline-block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
margin: 0px auto;
}

.navbar a:hover {
background: #f1f1f1;
color: black;
}
.fieldset-auto-width {
     display: inline-block;
}
form {
position: absolute;
z-index: 2;
left: 50px;
right: 50px;
}
</style>
 <link rel="STYLESHEET" type="text/css" href="contact.css" />
 <script type='text/javascript' src='scripts/gen_validatorv31.js'></script>
 <script type='text/javascript' src='scripts/fg_captcha_validator.js'>
</script>
 <link rel="icon" href="http://localhost/alpha.png" type="image/png" 
sizes="16x16">
</head>
<body>
<div id="background-image"></div>

 <!-- Form Code Start -->
<center><form id='contactus' action='<?php echo $formproc->GetSelfScript(); 
?>' method='post' enctype="multipart/form-data" accept-charset='UTF-8'>
<fieldset class="fieldset-auto-width">
<legend><h1>Contact Alpha Boss Computer Services</h1></legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' 
value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text'  class='spmhidip' name='<?php echo $formproc-
>GetSpamTrapInputName(); ?>' />
<div class='short_explanation'><font size="3" color="navy"><h1>* required 
fields</h1></font></div>
<div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span>
</div>
<div class='container'>
<label for='name'><font size="3" color="navy"><h1>Your Full Name Below*:
</h1></font></label><br/>
<input style='width:400px;height:40px;font-size:14pt; border:3px solid 
black' type='text' name='name' id='name' value='<?php echo $formproc-
>SafeDisplay('name') ?>' maxlength="50" /><br/>
<span id='contactus_name_errorloc' class='error'></span>
</div>
 <div class='container'>
<label for='email'><font size="3" color="navy"><h1>Your Email Address 
Below*:</h1></font></label><br/>
<input style='width:400px;height:40px;font-size:14pt; border:3px solid 
black' type='text' name='email' id='email' value='<?php echo $formproc-
>SafeDisplay('email') ?>' maxlength="50" /><br/>
<span id='contactus_email_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='message'><font size="3" color="navy"><h1>Your Message Below:
</h1></font></label><br/>
<span id='contactus_message_errorloc' class='error'></span>
<textarea rows="10" cols="50" name='message' id='message' style="border:3px 
solid black"><?php echo $formproc->SafeDisplay('message') ?></textarea>
</div>
<div class='container'>
<label for='photo'><font size="3" color="navy"><h1>Upload your photos:</h1>
</font></label><br/>
<input type="file" name='photo[]' id='photo' multiple=""/><br/>
</div>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
</fieldset>
</form></center>
<h1>You can call <u>289-696-7530</u></h1>
<div class="navbar">
<div class="navbar-inner">
<a href="index.html">HOME</a>       
<a href="https://www.facebook.com/Alpha-Boss-Computer-Services-
1259286717548256/">FACEBOOK PAGE</a>
</div>
</div>
<!-- client-side Form Validations:
Uses the excellent form validation script from JavaScript-coder.com-->

<script type='text/javascript'>
// <![CDATA[

var frmvalidator  = new Validator("contactus");
frmvalidator.EnableOnPageErrorDisplay();
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("name","req","Please provide your name");

frmvalidator.addValidation("email","req","Please provide your email 
address");

frmvalidator.addValidation("email","email","Please provide a valid email 
address");

frmvalidator.addValidation("message","maxlen=2048","The message is too long!
(more than 2KB!)");

frmvalidator.addValidation("photo","file_extn=jpg;jpeg;gif;png;bmp","Upload 
images only. Supported file types are: jpg,gif,png,bmp");
// ]]>
</script>

</body>
</html>

@Wr1t3r 这是我更新的 fgcontactform.php 代码我希望这有助于你更好地理解。我还收到了http://www.html-form-guide.com/contact-form/contact-form-attachment.html的联系表格。

【问题讨论】:

标签: php email photo


【解决方案1】:

将您的文件输入命名为 photo[],这样您的 php 就可以遍历文件数组。

<input type="file" name='photo[]' id='photo' multiple=""/>

【讨论】:

  • 您好,我确实添加了照片[],当我提交表格并将文件上传到我的迅雷邮箱时,我没有收到任何附件。
  • 那不是完成的代码。您需要继续在 php.ini 中循环所有选定的文件。例如,您在此行仅添加一张照片 $formproc->AddFileUploadField('photo','jpg,jpeg,gif,png,bmp',2024);更改它,使其遍历文件数组并添加所有文件。
  • @Wrt3r 我更新了 php 文件并在foreach ($_FILES['name']['photo'] as $file) { 之后添加了:if(isset($_FILES['submit'])){ // Count total files $formproc = count($_FILES['photo']['name']); // Looping all files for($i=0;$i&lt;$fromproc;$i++){ $file = $_FILES['photo']['name'][$i]; // Upload file move_uploaded_file($_FILES['photo']['tmp_name'][$i],'submit/'.$file); 我尝试再次将其发送到我的雷鸟电子邮件但仍然没有收到任何附件我不确定我是否这样做正确与否。
  • @AndrewAristizabal 你能在你原来的问题中显示来自 fgcontactform.php 的代码吗?你的循环不好,对我来说没有意义:)
  • 我已经在我原来的问题中更新了上面的 fgcontactform.php 代码我希望你能更好地理解它我还在原来的问题中添加了链接到我原来找到联系表的地方 好的谢谢.
猜你喜欢
  • 1970-01-01
  • 2020-01-13
  • 1970-01-01
  • 2013-07-28
  • 1970-01-01
  • 2016-11-22
  • 1970-01-01
  • 2014-12-19
  • 1970-01-01
相关资源
最近更新 更多