Created
September 16, 2018 23:59
-
-
Save SirmaXX/91995b97c4a14bb4f0c1162a83241e9c to your computer and use it in GitHub Desktop.
php7+ pdo multiupload with mysql order form example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ı inspired this solution from https://daveismyname.blog/upload-multiple-files-with-a-single-input-with-html-5-and-php | |
main solution in this link,if you use bootstrap 4 you can see html elements | |
Bu sorunun temel çözümü yukarıdaki linktedir | |
bootstrap kullanarak html elementleri görebilirsiniz | |
<?php | |
güvenlik için bir fonksiyon/security function | |
function clean($data) { | |
$data = trim($data); | |
$data = stripslashes($data); | |
$data = htmlspecialchars($data); | |
return $data; | |
} | |
if(isset($_POST['btn-add'])) | |
{ | |
$email=clean($_POST['email']); | |
$telno=clean($_POST['telno']); | |
$detail=clean($_POST['detail']); | |
$adsoy=clean($_POST['adsoyad']); | |
if(count($_FILES['simages']['name']) > 1){ | |
//Loop through each file | |
for($i=0; $i<count($_FILES['image']['name']); $i++) { | |
//Get the temp file path | |
$tmpFilePath = $_FILES['image']['tmp_name'][$i]; | |
$shortname = $_FILES['image']['name'][$i]; | |
$shortsize = $_FILES['image']['size'][$i]; | |
$imgExt=strtolower(pathinfo($shortname,PATHINFO_EXTENSION)); | |
$valid_extensions=array('jpeg', 'jpg', 'png'); | |
$maxsize=1024 *200; | |
if( $shortsize >= $maxsize) { | |
?> <script> | |
alert("resim boyutu büyük"); | |
</script> | |
<?php | |
}elseif(!in_array($imgExt,$valid_extensions)){ | |
?> | |
<script> | |
alert("sadece png jpg jpeg eklenebilir"); | |
</script> | |
<?php | |
} | |
else{ | |
$filePath = "uploadfolder/" . date('d-m-Y-H-i-s').'-'.$_FILES['image']['name'][$i]; | |
//Make sure we have a filepath | |
if($tmpFilePath != ""){ | |
if(move_uploaded_file($tmpFilePath, $filePath)) { | |
$files[] = $shortname; | |
$sql="INSERT INTO siparis(id,table1,table2) VALUES (NULL,'$email','$adsoy','$telno','$detail','$shortname')"; | |
$conn->exec($sql); | |
echo '<script>window.location.href="index.php"</script>'; | |
} | |
} | |
} | |
} | |
}else {//this query work without image | |
$sql="INSERT INTO siparis(id,table1,table2) VALUES (NULL,'$email','$adsoy','$telno','$detail')"; | |
$conn->exec($sql); | |
echo '<script>window.location.href="index.php"</script>'; | |
} | |
} | |
?> | |
<div class="container h-100"> | |
<form action="<?=$_SERVER['PHP_SELF']?>" role="form" method="post" enctype="multipart/form-data"> | |
<br> | |
<br> | |
<div class="row "> | |
<section class="col-6 h-25"> | |
<h2> | |
order form/sipariş formu | |
</h2> | |
<div class="form-group"> | |
<label for="email">Email Adresiniz:</label> | |
<input class="form-control form-control-lg" placeholder="Email" name="email" id="email" type="text" required> | |
</div> | |
<div class="form-group"> | |
<label for="phonenumber">Adınız Ve soyadınız:</label> | |
<input id="phonenumber" class="form-control form-control-lg" name="adsoyad" placeholder="Adınız Ve soyadınız" type="text" required> | |
</div> | |
<div class="form-group"> | |
<label for="phonenumber">Telefon Numarası:</label> | |
<input id="phonenumber" class="form-control form-control-lg" name="telno" placeholder="telefon numarası" type="text" required> | |
</div> | |
</section> | |
<section class="col-6 h-25"> | |
<div class="form-group"> | |
<label for="detail">order detail /sipariş detayı:</label> | |
<textarea class="form-control" name="detail" rows="5" id="detail" required ></textarea> | |
</div> | |
<p>İsterseniz resim ekleyerek siparişinizi detaylandırabilirsiniz. </p> | |
<hr> | |
<div class="col-lg-6 col-sm-6 col-12"> | |
<label class="btn btn-primary"> | |
Browse… | |
<input type="file" name="image[]" class="form-control" multiple accept="*/image"> | |
</label> | |
</div | |
<br> | |
<button type="submit" name="btn-add" class="btn btn-primary btn-block">Sipariş Gönder/send order</button> | |
</section> | |
</div> | |
</form> | |
</div> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment