I am making a system that manages PNG, JGP AND PDF files, the system is already functional, but when I try to upload a JPG file it does not work, with PNG it works the same as with PDF, but nothing happens when uploading a JPG file, this is my code.
<?php
include('conexion.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$title = $con->real_escape_string(htmlentities($_POST['title']));
$description = $con->real_escape_string(htmlentities($_POST['description']));
$file_name = $_FILES['file']['name'];
$new_name_file = null;
if ($file_name != '' || $file_name != null) {
$file_type = $_FILES['file']['type'];
list($type, $extension) = explode('/', $file_type);
if ($extension == 'pdf' || $extension == 'png' || $extension == 'jpg') {
$dir = 'files/';
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
$file_tmp_name = $_FILES['file']['tmp_name'];
//$new_name_file = 'files/' . date('Ymdhis') . '.' . $extension;
$new_name_file = $dir . file_name($file_name) . '.' . $extension;
if (copy($file_tmp_name, $new_name_file)) {
}
}
}
$ins = $con->query("INSERT INTO files(title,description,url) VALUES ('$title','$description','$new_name_file')");
if ($ins) {
echo 'success';
} else {
echo 'fail';
}
} else {
echo 'fail';
}
Also add
jpeg
it to the list of extensions, as it is also likely to sometimes returnimage/jpeg
:Change this:
For this: