コード例 #1
0
function resizeImg($arr)
{
    // name of the file here
    $date = md5(time());
    // upload image and resize
    $uploaddir = $arr['uploaddir'];
    $tempdir = $arr['tempdir'];
    $temp_name = $_FILES['photo']['tmp_name'];
    $img_parts = pathinfo($_FILES['photo']['name']);
    $new_name = strtolower($date . '.' . $img_parts['extension']);
    $ext = strtolower($img_parts['extension']);
    $allowed_ext = array('gif', 'jpg', 'jpeg', 'png');
    if (!in_array($ext, $allowed_ext)) {
        echo '<p class="uperror">' . $arr['fileError'] . '</p>';
        exit;
    }
    $temp_uploadfile = $tempdir . $new_name;
    $new_uploadfile = $uploaddir . $new_name;
    // less than 3MB default
    if ($_FILES['photo']['size'] < $arr['maxfilesize']) {
        if (move_uploaded_file($temp_name, $temp_uploadfile)) {
            /****** Check EXIF ******/
            // reading the image orientation
            if ($img_parts['extension'] == 'jpeg' || $img_parts['extension'] == 'jpg') {
                $arr['orientation'] = checkExifOrientation($temp_uploadfile);
            } else {
                $arr['orientation'] = 1;
            }
            /****** Check EXIF END ******/
            // add key value to arr
            $arr['temp_uploadfile'] = $temp_uploadfile;
            $arr['new_uploadfile'] = $new_uploadfile;
            $arr['web_file'] = $arr['web_dir'] . $new_name;
            asidoImg($arr);
            unlink($temp_uploadfile);
            exit;
        }
    } else {
        echo '<p class="uperror">' . $arr['sizeError'] . '</p>';
        exit;
    }
}
コード例 #2
0
ファイル: functions.php プロジェクト: parsonsc/dofe
/**
 * image resizing starts here
 * 
 * @param type $arr
 */
function resizeImg($arr)
{
    // name of the file here
    $date = md5(time());
    // upload image and resize
    $uploaddir = $arr['uploaddir'];
    $tempdir = $arr['tempdir'];
    $temp_name = $_FILES['afgyourfile']['tmp_name'];
    $img_parts = pathinfo($_FILES['afgyourfile']['name']);
    $new_name = strtolower($date . '.' . $img_parts['extension']);
    $ext = strtolower($img_parts['extension']);
    $allowed_ext = array('gif', 'jpg', 'jpeg', 'png');
    $expire = gmdate('D, d M Y H:i:s \\G\\M\\T', time() - 84600);
    header("Expires: " . $expire);
    echo '<html><head><meta http-Equiv="Cache-Control" Content="no-cache" /><meta http-Equiv="Pragma" Content="no-cache" /><meta http-Equiv="Expires" Content="' . $expire . '" /><body onload="window.parent.uploadDone();">';
    if (!in_array($ext, $allowed_ext)) {
        echo '<p class="uperror">' . $arr['fileError'] . '</p>';
        exit;
    }
    $temp_uploadfile = $tempdir . $new_name;
    $new_uploadfile = $uploaddir . $new_name;
    // less than 3MB default
    if ($_FILES['afgyourfile']['size'] < $arr['maxfilesize']) {
        if (move_uploaded_file($temp_name, $temp_uploadfile)) {
            // Check EXIF if jpeg
            if ($ext === 'jpg' || $ext === 'jpeg') {
                $arr['orientation'] = checkExifOrientation($temp_uploadfile);
            } else {
                $arr['orientation'] = 1;
            }
            // add key value to arr
            $arr['temp_uploadfile'] = $temp_uploadfile;
            $arr['new_uploadfile'] = $new_uploadfile;
            wideimageImg($arr);
            unlink($temp_uploadfile);
        }
    } else {
        echo '<p class="uperror">' . $arr['sizeError'] . '</p>';
    }
    echo '</body></html>';
    exit;
}