gpt4 book ai didi

php - 上传最小图片宽度和高度

转载 作者:行者123 更新时间:2023-12-01 07:35:45 25 4
gpt4 key购买 nike

所以我使用 Uplodify 插件来允许用户一次上传多个图像。问题是我需要设置图像的最小宽度和高度。假设 150x150px 是用户可以上传的最小图像。

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

这是上传图像的插件调用的 PHP 文件:

<?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:

$(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,使其不会上传尺寸非常小的图像。

最佳答案

您可以在此行获取图像的大小:

$size = getimagesize($pathToFullImage);

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

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

此外,Uploadify 似乎有一个 onError 选项,您可以设置:http://www.uploadify.com/documentation/

编辑:此线程看起来可能对您有一些帮助:http://www.uploadify.com/forum/viewtopic.php?f=5&t=14

关于php - 上传最小图片宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1942790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com