我有以下 php 代码,它允许用户上传图像。如何修改我的代码,以便对上传的图像大小有限制(比如说最大 800 k)。这是我的代码。
<?php
if (isset($_FILES['profile'])===true) {
if (empty($_FILES['profile']['name']) === true) {
echo'Please choose an Image File !';
} else {
$allowed = array('jpg', 'jpeg', 'gif', 'png');
$file_name = $_FILES['profile']['name'];
$file_extn = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
$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: ' . $current_file);
exit();
} else {
echo'Incorrect file type! Allowed:';
echo implode(', ', $allowed);
}
}
}
if (empty($user_data['profile'])=== false ) {
echo '<img src="', $user_data['profile'], '" alt="', $user_data['name'], ' - Profile Image">';
}
?>