Currently I am using this code to upload an image:
elseif ($_post['password'] == ''){
if($my_form->checkEmail($_POST['email'])) { // check for good mail
$allowedExts = array("gif", "jpeg", "jpg", "png");
$extension = end(explode(".", $_FILES["img"]["name"]));
if ((($_FILES["img"]["type"] == "image/gif")
|| ($_FILES["img"]["type"] == "image/jpeg")
|| ($_FILES["img"]["type"] == "image/jpg")
|| ($_FILES["img"]["type"] == "image/pjpeg")
|| ($_FILES["img"]["type"] == "image/x-png")
|| ($_FILES["img"]["type"] == "image/png"))
&& ($_FILES["img"]["size"] < 3145728)
&& in_array($extension, $allowedExts))
{
if ($_FILES["img"]["error"] <= 0)
{
move_uploaded_file($_FILES["img"]["tmp_name"], "upload/" . $user->userID.'.'.$extension);
}
}
I am using this code to show the image (it grabs the last modified file):
$avatars = glob("upload/$user->userID.*");
if(!empty($avatars)) {
$avatars = array_combine($avatars, array_map("filemtime", $avatars));
arsort($avatars);
$latest_avatar = key($avatars);
echo '<img style="width:20%;" src="'.$latest_avatar.'">';
echo '<p>**Note Image must be smaller than 3MB.</p>';
echo '<input type="submit" name="submit" value="Submit"></td></tr>';
I have seen some code around and have tried to use it, but I cannot get it to work... something like this:
$avatars = glob("upload/$user->userID.*");
if(!empty($avatars)) {
$avatars = array_combine($avatars, array_map("filemtime", $avatars));
arsort($avatars);
$latest_avatar = key($avatars);
function resample($latest_avatar, $thumbFile, $width, $orientation) {
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($latest_avatar);
$height = (int) (($width / $width_orig) * $height_orig);
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($latest_avatar);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Fix Orientation
switch($orientation) {
case 3:
$image_p = imagerotate($image_p, 180, 0);
break;
case 6:
$image_p = imagerotate($image_p, -90, 0);
break;
case 8:
$image_p = imagerotate($image_p, 90, 0);
break;
}
// Output
imagejpeg($image_p, $thumbFile, 90);
}
echo '<img style="width:20%;" src="'.$image_p.'">';
echo '<p>**Note Image must be smaller than 3MB.</p>';
echo '<input type="submit" name="submit" value="Submit"></td></tr>';
It comes out with nothing, img src is just blank. I get no errors... error reporting is enabled. If I take out the function and use echo '<img style="width:20%;" src="'.$latest_avatar.'">';
it works fine and shows the image, but of course it isn't rotated.
Can anyone help me with this?