Image resizer and uploader
Couple of things I've done to your code:


Early exits
Redundant code removal
Readability improvement


Keep in mind that I have not tested this, but it should work. And also, the code will only work on PHP 5.4 and greater.

Cleaned up version:

&lt;?php
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_FILES['icon'])) {
    echo 'Image upload failed.';

    return;
}

$file = [
    'name' =&gt; stripslashes($_FILES['icon']['name']),
    'path' =&gt; $_FILES['icon']['tmp_name'],
    'ext'  =&gt; strtolower(pathinfo($_FILES['icon']['name'], PATHINFO_EXTENSION)),
    'size' =&gt; filesize($_FILES['icon']['tmp_name'])
];

$supportedExts = [
    'jpg',
    'jpeg',
    'png',
    'gif'
];

if (!in_array($file['ext'], $supportedExts)) {
    echo 'Extension not supported.';

    return;
}

if ($file['size'] &gt; 400 * 1024) {
    echo 'You have exceeded the image size limit.';

    return;
}

list($image['x'], $image['y']) = getimagesize($file['path']);

switch ($file['ext']) {
    case 'jpg':
    case 'jpeg':
        $imgResrc1 = imagecreatefromjpeg($file['path']);
        break;
    case 'png':
        $imgResrc1 = imagecreatefrompng($file['path']);
        break;
    default:
        $imgResrc1 = imagecreatefromgif($file['path']);
}

$imageSizes = array(
    [
        'x' =&gt; 300,
        'y' =&gt; $image['y'] / $image['x'] * 300
    ],
    [
        'x' =&gt; 500,
        'y' =&gt; $image['y'] / $image['x'] * 500
    ]
);

foreach ($imageSizes as $size) {
    $imgResrc2 = imagecreatetruecolor($size['x'], $size['y']);

    imagecopyresampled($imgResrc2, $imgResrc1, 0, 0, 0, 0, $size['x'], $size['y'], $image['x'], $image['y']);

    // Shouldn't the extension be .jpg / .jpeg since you're using imagejpeg()?
    $filePath = 'usericons/' . $size['x'] . '-'. $_SESSION['username'] . '.png';

    imagejpeg($imgResrc2, $filePath, 100);

    imagedestroy($imgResrc2);
}

imagedestroy($imgResrc1);

hasIcon($_SESSION['username']);

echo '&lt;script&gt;window.location = \'/Users/\';&lt;/script&gt;';

// TODO: Print success message