因此,我使用Uplodify插件允許用戶一次上傳多個圖像。問題是我需要爲圖像設置最小寬度和高度。比方說,150x150px是用戶可以上傳的最小圖片。Uploadify最小圖像寬度和高度
如何在Uploadify插件中設置此限制?當用戶嘗試上傳較小的圖片時,我也想顯示一些錯誤消息。
這裏是被稱爲BU插件上傳圖片的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,因此它不會上傳尺寸非常小的圖像。
我我敢打賭,javascript無法讀取圖像尺寸。當你在javascript沙盒中時,從磁盤上的文件中讀取數據是嚴格苛刻的。如果你想在客戶端讀取這些東西,Flash或Java Applet可能是必需的。 – 2009-12-21 21:55:54
否。圖像上傳到服務器上的臨時文件夾,如果一切正常,則將它們保存到正常服務器位置以獲取圖像。我會對臨時圖像進行所有測試和檢查。我只需要知道如何訪問onComplete中的PHP響應......並且我無法從相當稀少的文檔中找到它。 – 2009-12-21 22:09:24