Need help resizing profile image in php
1. Right now, a user can upload a profile image in "profile" folder. If the user uploads a new profile image, it does that. However the old image is still stored in "profile" folder. How do I make sure that the old image is always deleted if a new image is uploaded?
2. I need to scale/resize the profile image. I can easily do it in css but that's not the right way. I have searched and found different ways to do it. However I am little lost on how it would fit in my code.
Below is my php code.
loggedin page
<?php
if (isset($_FILES['profile']) === true) {
if (empty($_FILES['profile']['name']) === true) {
echo "Please choose a file!";
} else {
$allowed = array('jpg', 'jpeg', 'gif', 'png');
$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: index.php');
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'], '\'s Profile Image">';
}
?>
function change_profile_image($user_id, $file_temp, $file_extn) {
$file_path = 'images/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);
}
So how do i go on about adding the image resize code?
-
man5 -
Thanks
Signaturewww.imdabest.ca{{ DiscussionBoard.errors[8644469].message }} -
-
man5 -
Thanks
Signaturewww.imdabest.ca{{ DiscussionBoard.errors[8646628].message }} -