私はphp
という連絡フォームを作成しました。名前、電子メール、およびメッセージの検証には効果がありますが、ファイルサイズの検証は機能しません。私が2MB以上のファイルをアップロードしようとすると、ロードされて崩壊します。 私は何をすべきか考えがなくなってしまった。誰でも助けてくれますか?添付ファイル付きの連絡フォームのPHPファイルサイズの確認
<?php
if ($_POST["submit"]) {
if (!$_POST['name']){
$error="Unesite svoje ime.";
}
if (!$_POST['email']) {
$error.="Unesite e-mail adresu.";
}
if (!$_POST['message']) {
$error.="Unesite tekst poruke";
}
if ($_POST['email']!="" AND !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) {
$error.="Unesite validu e-mail adresu.";
}
if(!empty($_FILES['my-file']['name'])){
$file_name = $_FILES['my-file']['name'];
$temp_name = $_FILES['my-file']['tmp_name'];
$file_type = $_FILES['my-file']['type'];
if($_FILES['my-file']['size'] > 524288){
$error.="Maksimalna velicina fajla je 5 MB.";
} else {
$from = $_POST['email'];
$to = "[email protected]";
$subject = "Poruka sa sajta";
$message = "Tekst poruke:".$_POST['message'];
$file = $temp_name;
$content = chunk_split(base64_encode(file_get_contents($file)));
$uid = md5(uniqid(time()));
$header = "MIME-Version: 1.0\r\n";
$header .= "From:".$from."\r\n";
$header .= "Reply-To: ".$_POST['email']."" . "\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
//plain text part
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
//attachment part
$header .= "--".$uid."\r\n";
$header .= "Content-type: ".$file_type."; name=\"".$file_name."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
if ($error) {
$result='<div class="alert alert-danger">'.$error.'</div>';
} else {
if (mail($to, $subject, "", $header)) {
$result='<div class="alert alert-success"><strong>Vasa poruka je poslata!</strong></div>';}
else {
$result='<div class="alert alert-danger">Došlo je do greške prilikom slanja poruke. Molim Vas pokušajte ponovo kasnije.</div>';}
} //if there is no error
}} else {if ($error) {
$result='<div class="alert alert-danger">'.$error.'</div>';
} else {
$header = "From:".$_POST['email']."\r\n";
$header = "Reply-To: ".$_POST['email']. "\n" ;
$body = "Tekst poruke:".$_POST['message'];
if (mail('[email protected]', 'Poruka sa sajta', $body, $header)) {
$result='<div class="alert alert-success"><strong>Vasa poruka je poslata!</strong></div>';}
else {
$result='<div class="alert alert-danger">Došlo je do greške prilikom slanja poruke. Molim Vas pokušajte ponovo kasnije.</div>';}
}}//if files not empty
} //if is submited
?>
と私のHTML
コード: はここに私のphp
コードです
<div class="col-md-6 emailForm">
<?php echo $result; ?>
<form id="contact_body" method="post" action="index.php" enctype="multipart/form-data">
<div class="form-group">
<label for="name">Ime i prezime:</label>
<input type="text" name="name" class="form-control" placeholder="Ime i prezime" data-required="true"/>
</div>
<div class="form-group">
<label for="email">E-mail:</label>
<input type="text" name="email" class="form-control" placeholder="E-mail" data-required="true"/>
</div>
<div class="form-group">
<label for="comment">Poruka:</label>
<textarea class="form-control" name="message" data-required="true"></textarea>
</div>
<div class="form-group">
<label class="btn btn-primary">
<input type="file" name="my-file" style="display:none;" onchange="$('#upload-file-info').html(this.files[0].name);">
Dodajte sliku
</label>
<span class='label label-info' id="upload-file-info"></span>
</div>
<div id="push" class="pushbutton"></div>
<input type="submit" name="submit" class="btn btn-lg" value="Poslati"/>
</form>
</div>
'もし($ _ FILES [ '私のファイル'] [ 'サイズ']>を追加します524288 ') '? –