im trying to create a forum in which you can upload images and im trying to add a mb limit. in my HTACCESS file i added:
php_value upload_max_filesize 51M
php_value post_max_size 53M
and in my file where i parse the data and send it to the database and also check for errors i have this:
<?php
session_start();
include '../assets/database.php';
if (isset($_POST['addPost'])) {
if (empty($_POST['titel']) || empty($_POST['bericht']) || empty($_FILES['file'])) {
$_SESSION['error'] = "Vul alle velden in!";
header('Location: ../forum');
exit();
}
if (strlen($_POST['titel']) > 50 || strlen($_POST['bericht']) > 250) {
$_SESSION['error'] = "Titel een maximum van 50 characters en bericht een maximum van 250 characters";
header('Location: ../forum');
exit();
}
if ($_FILES["file"]['size'] > 54525952) {
$_SESSION['error'] = "50mb Upload limiet";
header('Location: ../forum');
exit();
}
$name = $_FILES["file"]["name"];
$titel = $_POST['titel'];
$bericht = $_POST['bericht'];
$username = $_SESSION['username'];
$tempname = $_FILES["file"]["tmp_name"];
$target_dir = "../uploads/";
$allowedExtensions = ["jpg","jpeg","png","gif"];
if (move_uploaded_file($_FILES['file']['tmp_name'], $target_dir.$name)) {
$sql = $pdo->prepare("INSERT INTO posts (username, titel, bericht, file_name) VALUES (:username, :titel, :bericht, :file_name)");
$sql->bindParam('username', $username, PDO::PARAM_STR);
$sql->bindParam('titel', $titel, PDO::PARAM_STR);
$sql->bindParam('bericht', $bericht, PDO::PARAM_STR);
$sql->bindParam('file_name', $name, PDO::PARAM_STR);
$sql->execute();
header('Location: ../forum');
$_SESSION['filesize'] = $_FILES['file']['size'];
exit();
} else {
$_SESSION['error'] = "error file uploaden!";
header('Location: ../forum');
exit();
}
}
after i upload a file that is larger then 51 mb it does show a error but it is the standard php error which that says it is over the mb limit, it never shows my error