Pa help po ano po solution dito nag lahat kasing user lumalabas e gusto ko sana isa lang kaso di ko alam kung ano po yung sulution sana matulungan nyo po ako :>
code ng index.php
code ng upload.php
code ng index.php
Code:
<?php
$sql = 'select * from users';
$result = mysqli_query($link, $sql);
if (mysqli_num_rows($result) > 1) {
while ($row = mysqli_fetch_assoc($result)) {
$id = $row['id'];
$sqli = "select * from userlog";
$resultI = mysqli_query($link, $sqli);
while ($rowI = mysqli_fetch_assoc($resultI)) {
echo "<div class='image'>";
if ($rowI['status']==0) {
}
else{
echo "<img src='uploads/pic".$id.".jpg'>";
}
echo "<p>".$row['username']."</p>";
echo "</div>";
}
}
}
echo "<form action='upload.php' method='POST' enctype='multipart/form-data'>
<input type='file' name='file'>
<button type='submit' name='submit'>Upload</button>
</form>";
?>
Code:
<?php
session_start();
include_once 'db.php';
$id = $_SESSION['id'];
if (isset($_POST['submit'])) {
$files = $_FILES['file'];
$name = $_FILES['file']['name'];
$tmp = $_FILES['file']['tmp_name'];
$size = $_FILES['file']['size'];
$error = $_FILES['file']['error'];
//first error handling - allow the user to upload only jpg, jpeg and png
$fileExt = explode('.', $name); // user.jpg -> [0] = user , [1] = jpg
$ActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png');
if (in_array($ActualExt, $allowed)) {
if($error === 0){
if($size < 1000000){
$newName = 'Pic'.$id.".".$ActualExt;
$dest = "uploads/".$newName;
move_uploaded_file($tmp, $dest);
$sql = "update profile set status=0 where userid='$id';";
mysqli_query($link, $sql);
header("location: index.php");
} else{
echo "You file is too big.";
}
} else{
echo "You have an error upload the file.";
}
} else{
echo "You cannot Upload a file in that extention.";
}
}
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.