我想在这个PHP代码上设置我自己的附件大小限制。 我尝试了很多代码,但一切都不起作用。
你能帮我吗?我应该在那里使用什么工作代码? 我想将最大大小设置为2MB,并且应该有消息,,抱歉,此附件太大(否则 - 用于检查它是否正常工作("。
以及如何确定要附加的类型?例如,我只想上传PNG和JPG。如何在我的代码上执行此操作?并且也应该有消息,例如 - ,,对不起,您只能附加 PNG 和 JPG 文件。
注意!一切正常。我只想更改上传大小并使 PNG 和 JPG 文件:)谢谢!
这是我的PHP代码:
<?php
iconv_set_encoding("internal_encoding", "UTF-8");
$headers .= 'Content-type: text/html; charset=utf-8' . "rn";
if(!empty($_POST["send"])) {
require_once ('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = TRUE;
$mail->Port = 587;
$mail->Username = "wlasciciel@rubinmc.pl";
$mail->Password = "XXXXXXXXX";
$mail->Mailer = "smtp";
if (isset($_POST["userEmail"])) {
$userEmail = $_POST["userEmail"];
}
if (isset($_POST["userName"])) {
$userName = $_POST["userName"];
}
if (isset($_POST["subject"])) {
$subject = $_POST["subject"];
}
if (isset($_POST["userMessage"])) {
$message = $_POST["userMessage"];
}
if (isset($_POST["NickCheatera"])) {
$NickCheatera = $_POST["NickCheatera"];
}
$mail->SetFrom('wlasciciel@rubinmc.pl', $userName);
$mail->AddReplyTo($userEmail, $userName);
$mail->AddAddress("wlasciciel@rubinmc.pl"); // set recipient email address
$mail->Subject = 'Zgloszenie';
$mail->Body = join('', array(
'Wiadomosc od: ',
$_POST['userName'],
'<br/>',
'E-mail: ',
$_POST['userEmail'],
'<br/>',
'Nick cheatera: ',
$_POST['NickCheatera'],
'<br/>',
'Powod: ',
$_POST['subject'],
'<br/>',
'Dodatkowe informacje: ',
'<br/>',
$_POST['userMessage'],
'<br/>'
));
$mail->WordWrap = 80;
$mail->IsHTML(true);
$mail->SMTPSecure = 'tls';
$mail->Host = 'serwer2092488.home.pl';
if (! empty($_FILES['attachment'])) {
$count = count($_FILES['attachment']['name']);
if ($count > 0) {
// Attaching multiple files with the email
for ($i = 0; $i < $count; $i ++) {
if (! empty($_FILES["attachment"]["name"])) {
$tempFileName = $_FILES["attachment"]["tmp_name"][$i];
$fileName = $_FILES["attachment"]["name"][$i];
$mail->AddAttachment($tempFileName, $fileName);
}
}
}
}
if (! $mail->Send()) {
$message = "Wystąpił problem podczas wysyłania e-maila. Spróbuj ponownie.";
$type = "error";
} else {
$message = "Dziękujemy za zgłoszenie! Odpowiemy do 24 godzin.";
$type = "success";
}
}
网页代码:
<?php
require_once "mail-sending-script.php";
iconv_set_encoding("internal_encoding", "UTF-8");
$headers .= 'Content-type: text/html; charset=utf-8' . "rn";
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="style.css" rel="stylesheet" type="text/css" />
<title>RubinMC - zgłoś cheatera</title>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"
type="text/javascript"></script>
<script type="text/javascript">
function validate() {
var valid = true;
$(".info").html("");
var userName = document.forms["mailForm"]["userName"].value;
var userEmail = document.forms["mailForm"]["userEmail"].value;
var NickCheatera = document.forms["mailForm"]["NickCheatera"].value;
var subject = document.forms["mailForm"]["subject"].value;
var userMessage = document.forms["mailForm"]["userMessage"].value;
if (userName == "") {
$("#userName-info").html("(To pole jest wymagane.)");
$("#userName").css('background-color', '#FFFFDF');
valid = false;
}
if (userEmail == "") {
$("#userEmail-info").html("(To pole jest wymagane.)");
$("#userEmail").css('background-color', '#FFFFDF');
valid = false;
}
if (!userEmail.match(/^([w-.]+@([w-]+.)+[w-]{2,4})?$/))
{
$("#userEmail-info").html("(Zły format e-maila.)");
$("#userEmail").css('background-color', '#FFFFDF');
valid = false;
}
if (NickCheatera == "") {
$("#NickCheatera-info").html("(To pole jest wymagane.)");
$("#NickCheatera").css('background-color', '#FFFFDF');
valid = false;
}
if (subject == "") {
$("#subject-info").html("(To pole jest wymagane.)");
$("#subject").css('background-color', '#FFFFDF');
valid = false;
}
if (userMessage == "") {
$("#userMessage-info").html("(To pole jest wymagane.)");
$("#userMessage").css('background-color', '#FFFFDF');
valid = false;
}
return valid;
}
</script>
</head>
<body>
<h1 style="text-align: center">Zgłoś cheatera</h1>
<div class="attachment-form-container">
<form name="mailForm" id="mailForm" method="post" action=""
enctype="multipart/form-data" onsubmit="return validate()">
<div class="input-row">
<label style="padding-top: 20px;">Nick</label> <span
id="userName-info" class="info"></span><br /> <input
type="text" class="input-field" placeholder="Wpisz swój nick..." name="userName"
id="userName" />
</div>
<div class="input-row">
<label>E-mail</label> <span id="userEmail-info"
class="info"></span><br /> <input type="text"
class="input-field" name="userEmail" placeholder="Wpisz adres e-mail..."
id="userEmail" />
</div>
<div class="input-row">
<label>Nick cheatera</label> <span id="NickCheatera-info"
class="info"></span><br /> <input type="text"
class="input-field" name="NickCheatera" placeholder="Wpisz nick cheatera..."
id="NickCheatera" />
</div>
<div class="input-row">
<label for="subject">Powód</label>
<select id="subject" name="subject" class="input-field">
<option disabled selected>Wybierz powód</option>
<option id="Spam">Spam</option>
<option id="X-Ray">X-Ray</option>
<option value="Sales3">Sales2</option>
</select>
</div>
<div class="input-row">
<label>Dodatkowe informacje</label> <span id="userMessage-info"
class="info"></span><br />
<textarea name="userMessage" id="userMessage"
class="input-field" id="userMessage" placeholder="Wpisz dodatkowe informacje..."
cols="60"
rows="6"></textarea><br />
<label>Dodaj załącznik</label>
</div>
<div class="attachment-row">
<input type="file" class="input-field"
name="attachment[]">
</div>
<div>
<input type="submit" name="send" style="position: relative; left: 210px" class="btn-
submit"
value="Wyślij" />
<div id="statusMessage">
<?php
if (! empty($message)) {
?>
<p class='<?php echo $type; ?>Message'><?php echo $message; ?></p>
<?php
}
?>
</div>
</div>
</form>
</div>
<script>
$(document).ready(function() {
var inputPreview = $(".input-preview"),
input = $(".input");
TweenMax.set(input, {
scale: 1.2,
alpha: 0
});
inputPreview.on("click", function(){
var that = $(this);
that.toggleClass("active");
if(that.hasClass("active")){
TweenMax.staggerTo(input, 1.25, {
scale: 1,
alpha: 1,
ease: Elastic.easeOut
}, .1);
}
else {
TweenMax.staggerTo(input, 1, {
scale: 1.2,
alpha: 0,
ease: Elastic.easeOut
}, .1);
}
});
input.on("click", function() {
var tlInput = new TimelineMax({
onComplete: done
});
var that = $(this),
siblings = that.siblings(".input"),
data = that.data("val"),
top = that.css("top");
siblings.removeClass("active");
tlInput.to(siblings, .25, {
alpha: 0
})
.to(that, .25, {
scale: 1.2
})
.to(that, .25, {
top: 0,
})
.set(inputPreview, {
display: "none"
})
.to(that, .25, {
scale: 1,
})
.to(that, .5, {
backgroundColor: "#1D77EF"
})
.set(inputPreview, {
text: data,
display: "block"
})
.to(that, .25, {
alpha: 0
})
function done() {
inputPreview.removeClass("active");
that.css("top", top).addClass("active");
TweenMax.set(input, {
scale: 1.2,
alpha: 0,
backgroundColor: "#fff"
});
}
});
// copy
balapaCop("Select Input Interaction", "rgba(255,255,255,.5)");
});
</script>
</body>
</html>
尝试在 php.ini 中更改upload_max_filesize。