Skip to content

Instantly share code, notes, and snippets.

@djoudi
Last active March 28, 2023 11:04
Show Gist options
  • Save djoudi/ab7e6ead951e32d41ffe7fb33c9046fd to your computer and use it in GitHub Desktop.
Save djoudi/ab7e6ead951e32d41ffe7fb33c9046fd to your computer and use it in GitHub Desktop.
<?php
include "inc/header.php";
?>
<div class="productForm">
<form method="POST" action="addOk.php" enctype="multipart/form-data">
<div class="input">
<input type="text" name="nom" placeholder="Nom">
</div>
<div class="input">
<input type="text" name="prix" placeholder="Prix">
</div>
<div class="input">
<input type="text" name="qty" placeholder="Qty">
</div>
<div class="input">
<input type="file" name="photo" >
</div>
<button type="submit">Add</button>
</form>
</div>
<?php
include "inc/footer.php";
?>
<?php
require "inc/config.php";
$nom = (isset($_POST['nom']))?$_POST['nom']:NULL;
$prix = (isset($_POST['prix']))?$_POST['prix']:NULL;
$qty = (isset($_POST['qty']))?$_POST['qty']:NULL;
/* Upload File Start */
$upload = "up";
$myExts = ["png","jpg","jpeg","svg"];
if(!empty($_FILES)){
$name = $_FILES['photo']['name'];
$ext = @end(explode(".", $name));
if (in_array($ext,$myExts)) {
$mypoto = time().'.'.$ext;
$is_up = move_uploaded_file($_FILES['photo']['tmp_name'], $upload.DIRECTORY_SEPARATOR.$mypoto);
}else{
echo '<h3>Not Allowed</h3>';
}
}
/* Upload File End */
//echo $nom;
$sql = "INSERT INTO produits(id,nom,prix,qty,photo) VALUES(null,'$nom',$prix,$qty,'$mypoto')";
$q = mysqli_query($handel,$sql);
if ($q) {
header("Location:add.php");
}else{
die(mysqli_error($handel));
}
?>
<?php
require "inc/config.php";
$sql = "SELECT * FROM produits";
$q = mysqli_query($handel,$sql);
/*$data = mysqli_fetch_array($q,MYSQLI_ASSOC);
echo '<pre>';
print_r($data);
echo '</pre>';
*/
/*while ($data = mysqli_fetch_array($q,MYSQLI_ASSOC)) {
echo '<pre>';
print_r($data);
echo '</pre>';
echo '<hr>';
}*/
?>
<!-- .products>.product*4>img+h4 -->
<div class="products">
<?php
while ($data = mysqli_fetch_array($q,MYSQLI_ASSOC)) {
?>
<div class="product">
<img src="up/<?php echo $data['photo'] ?>" alt="">
<h4>Nom :<?php echo $data['nom'] ?></h4>
<h4>Prix :<?php echo $data['prix'] ?></h4>
<h4>Qty :<?php echo $data['qty'] ?></h4>
</div>
<?php
}
?>
</div>
<?php
include "inc/header.php";
$upload = "up";
$myExts = ["png","jpg","jpeg","svg","tif"]; //files.docx
// todo if ....
if(!empty($_FILES)){
$name = $_FILES['photo']['name'];
//echo $name; // ecoin.dz.web.png
//"004.jpg" ==> ["004","jpg"]
$ext = @end(explode(".", $name));
if (in_array($ext,$myExts)) {
$mypoto = time().'.'.$ext;
$is_up = move_uploaded_file($_FILES['photo']['tmp_name'], $upload.DIRECTORY_SEPARATOR.$mypoto);
}else{
echo '<h3>Not Allowed</h3>';
}
/* echo '<pre>';
print_r($ext);
echo '</pre>';*/
}
//$photo = (isset($_POST['photo']))?$_POST['photo']:null;
//echo $photo;
/*echo '<pre>';
print_r($_FILES);
echo '</pre>';*/
//echo $_FILES['photo']["size"];
?>
<div class="productForm">
<form method="POST" action="" enctype="multipart/form-data">
<div class="input">
<input type="file" name="photo" >
</div>
<button type="submit">Upload</button>
</form>
</div>
<?php
include "inc/footer.php";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment