Uploadify最小图像宽度和高度 [英] Uploadify Minimum Image Width And Height

查看:141
本文介绍了Uploadify最小图像宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在使用Uplodify插件,允许用户一次上传多张图片.问题是我需要为图像设置最小宽度和高度.假设150x150像素是用户可以上传的最小图像.

So I am using the Uplodify plugin to allow users to upload multiple images at once. The problem is I need to set a minimum width and height for images. Let's say 150x150px is the smallest image users can upload.

如何在Uploadify插件中设置此限制?当用户尝试上传较小的图片时,我也想显示一些错误消息.

How can I set this limitation in the Uploadify plugin? When user tries to upload smaller picture, I would like to display some error message as well.

这是一个名为bu的php文件,用于上传图片:

Here is the PHP file that is called bu the plugin to upload images:

<?php

define('BASE_PATH', substr(dirname(dirname(__FILE__)), 0, -22));

// set the include path
set_include_path(BASE_PATH
                 . '/../library'
                 . PATH_SEPARATOR
                 . BASE_PATH
                 . '/library'
                 . PATH_SEPARATOR
                 . get_include_path());

// autoload classes from the library
function __autoload($class) {
    include str_replace('_', '/', $class) . '.php';
}

$configuration = new Zend_Config_Ini(BASE_PATH
                                     . '/application'
                                     . '/configs/application.ini',
                                     'development');
$dbAdapter = Zend_Db::factory($configuration->database);
Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter);

function _getTable($table)
{
    include BASE_PATH
    . '/application/modules/default/models/'
    . $table
    . '.php';
    return new $table();
}

$albums = _getTable('Albums');
$media = _getTable('Media');

if (false === empty($_FILES)) {

    $tempFile = $_FILES['Filedata']['tmp_name'];
    $extension = end(explode('.', $_FILES['Filedata']['name']));

    // insert temporary row into the database
    $data = array();
    $data['type'] = 'photo';
    $data['type2'] = 'public';
    $data['status'] = 'temporary';
    $data['user_id'] = $_REQUEST['user_id'];
    $paths = $media->add($data, $extension, $dbAdapter);

    // save the photo
    move_uploaded_file($tempFile,
                       BASE_PATH . '/public/' . $paths[0]);

    // create a thumbnail
    include BASE_PATH . '/library/My/PHPThumbnailer/ThumbLib.inc.php';
    $thumb = PhpThumbFactory::create(BASE_PATH . '/public/' . $paths[0]);
    $thumb->adaptiveResize(85, 85);
    $thumb->save(BASE_PATH . '/public/' . $paths[1]);

    // add watermark to the bottom right corner
    $pathToFullImage = BASE_PATH . '/public/' . $paths[0];
    $size = getimagesize($pathToFullImage);
    switch ($extension) {
        case 'gif':
            $im = imagecreatefromgif($pathToFullImage);
            break;
        case 'jpg':
            $im = imagecreatefromjpeg($pathToFullImage);
            break;
        case 'png':
            $im = imagecreatefrompng($pathToFullImage);
            break;
    }
    if (false !== $im) {
        $white = imagecolorallocate($im, 255, 255, 255);
        $font = BASE_PATH . '/public/fonts/arial.ttf';
        imagefttext($im,
                    13, // font size
                    0, // angle
                    $size[0] - 132, // x axis (top left is [0, 0])
                    $size[1] - 13, // y axis
                    $white,
                    $font,
                    'HunnyHive.com');
        switch ($extension) {
            case 'gif':
                imagegif($im, $pathToFullImage);
                break;
            case 'jpg':
                imagejpeg($im, $pathToFullImage, 100);
                break;
            case 'png':
                imagepng($im, $pathToFullImage, 0);
                break;
        }
        imagedestroy($im);
    }

    echo "1";

}

这是javascript:

And here's the javascript:

$(document).ready(function() {    
    $('#photo').uploadify({
        'uploader'       : '/flash-uploader/scripts/uploadify.swf',
        'script'         : '/flash-uploader/scripts/upload-public-photo.php',
        'cancelImg'      : '/flash-uploader/cancel.png',
        'scriptData'     : {'user_id' : 'USER_ID'},
        'queueID'        : 'fileQueue',
        'auto'           : true,
        'multi'          : true,
        'sizeLimit'      : 2097152,
        'fileExt'        : '*.jpg;*.jpeg;*.gif;*.png',
        'wmode'          : 'transparent',
        'onComplete'     : function() {
            $.get('/my-account/temporary-public-photos', function(data) {
                $('#temporaryPhotos').html(data);
            });
        }
    });
    $('#upload_public_photo').hover(function() {
        var titles = '{';
        $('.title').each(function() {
            var title = $(this).val();
            if ('Title...' != title) {
                var id = $(this).attr('name');
                id = id.substr(5);
                title = jQuery.trim(title);
                if (titles.length > 1) {
                    titles += ',';
                }
                titles += '"' + id + '"' + ':"' + title + '"';
            }
        });
        titles += '}';
        $('#titles').val(titles);
    });
});

现在请记住,我知道如何检查PHP文件中的图像尺寸.但是我不确定如何修改javascript,因此它不会上传尺寸非常小的图片.

Now bear in mind that I know how to check images dimensions in the PHP file. But I'm not sure how to modify the javascript so it won't upload images with very small dimensions.

推荐答案

您将在此行上获得图像的大小:

You get the size of the image on this line:

$size = getimagesize($pathToFullImage);

为什么不在此处添加条件来检查它是否至少是您想要的大小,如果没有,则返回错误.

Why not add a conditional here to check if it is at least the size you want, and if not return an error.

if($size[0] > 150 || $size[1] > 150) {
  return $someError;
}

另外,似乎可以为Uploadify设置onError选项: http://www. uploadify.com/documentation/

Also it looks like there is an onError option for Uploadify which you could set: http://www.uploadify.com/documentation/

编辑:该线程可能会对您有所帮助:

This thread looks like it could be of some help to you: http://www.uploadify.com/forum/viewtopic.php?f=5&t=14

这篇关于Uploadify最小图像宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆