uploaded po pero 0byte kaya di nagrereflect.
<?php
include 'includes/session.php';
if(isset($_POST['add'])){
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$position = $_POST['position'];
$platform = $_POST['platform'];
$filename = $_FILES['photo']['name'];
if(!empty($filename)){
move_uploaded_file($_FILES['photo']['tmp_name'], '../images/'.$filename);
}
$sql = "INSERT INTO candidates (position_id, firstname, lastname, photo, platform) VALUES ('$position', '$firstname', '$lastname', '$filename', '$platform')";
if($conn->query($sql)){
$_SESSION['success'] = 'Candidate added successfully';
}
else{
$_SESSION['error'] = $conn->error;
}
}
else{
$_SESSION['error'] = 'Fill up add form first';
}
header('location: candidates.php');
?>
include 'includes/session.php';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if(isset($_POST['add'])){
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$position = $_POST['position'];
$platform = $_POST['platform'];
$filename = $_FILES['photo']['name'];
if(!empty($filename)){
$target_dir = '../images/';
$target_file = $target_dir . basename($filename);
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
// Check if file is an actual image
$check = getimagesize($_FILES['photo']['tmp_name']);
if($check === false) {
$_SESSION['error'] = 'File is not an image.';
header('location: candidates.php');
exit();
}
// Check for file upload errors
if ($_FILES['photo']['error'] > 0) {
$_SESSION['error'] = 'File upload error: ' . $_FILES['photo']['error'];
header('location: candidates.php');
exit();
}
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target_file)){
$sql = "INSERT INTO candidates (position_id, firstname, lastname, photo, platform) VALUES ('$position', '$firstname', '$lastname', '$filename', '$platform')";
if($conn->query($$sql)){
$_SESSION['success'] = 'Candidate added successfully';
}
else{
$_SESSION['error'] = 'Database error: ' . $conn->error;
}
} else {
$_SESSION['error'] = 'Moved uploaded file error.';
}
} else {
$_SESSION['error'] = 'File name is empty.';
}
} else {
$_SESSION['error'] = 'Fill up add form first';
}
header('location: candidates.php');
?>
<?php
include 'includes/session.php';
if(isset($_POST['upload'])){
$id = $_POST['id'];
$filename = $_FILES['photo']['name'];
if(!empty($filename)){
move_uploaded_file($_FILES['photo']['tmp_name'], '../images/'.$filename);
}
$sql = "UPDATE candidates SET photo = '$filename' WHERE id = '$id'";
if($conn->query($sql)){
$_SESSION['success'] = 'Photo updated successfully';
}
else{
$_SESSION['error'] = $conn->error;
}
}
else{
$_SESSION['error'] = 'Select candidate to update photo first';
}
header('location: candidates.php');
?>
-------------------------
<?php
include 'includes/session.php';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if(isset($_POST['upload'])){
$id = $_POST['id'];
$filename = $_FILES['photo']['name'];
if(!empty($filename)){
$target_dir = '../images/';
$target_file = $target_dir . basename($filename);
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
// Check if file is an actual image
$check = getimagesize($_FILES['photo']['tmp_name']);
if($check === false) {
$_SESSION['error'] = 'File is not an image.';
header('location: candidates.php');
exit();
}
// Check for file upload errors
if ($_FILES['photo']['error'] > 0) {
$_SESSION['error'] = 'File upload error: ' . $_FILES['photo']['error'];
header('location: candidates.php');
exit();
}
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target_file)){
$sql = "UPDATE candidates SET photo = '$filename' WHERE id = '$id'";
if($conn->query($sql)){
$_SESSION['success'] = 'Photo updated successfully';
} else {
$_SESSION['error'] = $conn->error;
}
} else {
$_SESSION['error'] = 'Moved uploaded file error.';
}
} else {
$_SESSION['error'] = 'File name is empty.';
}
} else {
$_SESSION['error'] = 'Select a candidate to update photo first';
}
header('location: candidates.php');
?>
-------------------
pa try nga ko boss pa edit ng code mo