All image extensions not accepted with php?

I am trying to upload my files to the profile / directory on my server and I believe that everything can work ... however, when downloading it thinks that my jpeg png and gif are not the correct file type. Why is this done. What is wrong here? How to fix it?

function change_profile_image($user_id, $file_temp, $file_extn) { $file_path = 'profile/' . substr (md5(time()), 0, 10) . '.' . $file_extn; move_uploaded_file($file_temp, $file_path); mysql_query("UPDATE `users` SET `profile` = " . mysql_real_escape_string($file_path) . "' WHERE `user_id` = " . (int)$user_id); } if (isset($_FILES['profile']) === true) { if (empty($_FILES['profile']['name']) === true) { echo 'yu no choose file!'; } else { $allowed = array ('jpg', 'jpeg', 'gif', 'png'); //this is the part i think may be brocken. $file_name = $_FILES['profile']['name']; $file_extn = strtolower(end(explode (' . ', $file_name))); $file_temp = $_FILES['profile']['tmp_name']; if (in_array($file_extn, $allowed) === true) { change_profile_image($session_user_id, $file_temp, $file_extn); header('Location: dontdelete.php'); exit(); }else { echo 'yu no jpg or png or gif'; } } } if (empty($user_data['profile']) === false) { echo '<img src"', $user_data['profile'], '" alt="">'; } 
+4
source share
1 answer

Change explode (' . ', $file_name) to explode ('.', $file_name)

also you need to check its actual image, and not just the image extension.

In addition, you will lose = in your output img, and you can also perform the casatization instead of the echo 3 times:

echo '<img src="'.$user_data['profile'].'" alt="">';

+3
source

Source: https://habr.com/ru/post/1445665/


All Articles