我用Uploadify上传图片。我面临的唯一问题是我想限制上传图像的用户的图像尺寸。(由于某些原因,我不想使用图像调整大小)。我在php中这样做的逻辑是,我有一个用户定义的函数,它将接受三个参数:第一个是图像tempname,第二个是要限制的图像宽度,第三个是要限制用户的图像高度。
function valid_image($image, $width, $height = 0) {
/** Get the Dimensions of the Uploaded Image **/
list($image_width, $image_height) = getimagesize($image['tmp_name']);
/** If the height parameter in function is skipped then perform this **/
if( $height == '0') {
if( $image_width !== $width) {
return false;
}
}
/** If all the parameters in the function has got the value then perform this **/
else if($image_width !== $width || $image_height !== $height) {
return false;
}
return true;
}
我想对uploadify应用相同的规则。
这是我上传的Jquery脚本。
//Uploadify File1
$(document).ready(function() {
$('#nstitle').uploadify({
'uploader': 'images/uploadify.swf',
'script': 'uploadify.php',
'folder': 'upload',
'auto' : 'true',
'cancelImg': 'images/cancel.png',
'fileDesc': 'jpg/jpeg',
'displayData': 'percentage',
'fileExt': "*.jpg;*.jpeg",
'sizeLimit' : '8388608',
'fileDataName' : 'nstitle',
onComplete: function(event, queueID, fileObj, response, data)
{
$('#t_fileUploadName').append('<p>'+response+'<p/>');
$("#t_fileUploadField").append("<input type='hidden' name='nstitle' value='" + response + "' />");
$("#t_fileUploadBtn").remove();
}
}); });
现在,如果uploadify不满足中的条件,我希望uploadify生成错误上传.php我做了这样的事。
if (!empty($_FILES['nstitle'])) {
$tempFile = $_FILES['nstitle']['tmp_name'];
if(!valid_image($_FILES['nstitle'],685 , 50)) {
echo "Incorrect File Dimension";
die();
}
else {
$targetPath = 'uploads/news/title/';
move_uploaded_file($tempFile,$targetPath.$ns_title);
echo "$targetPath$ns_title";
}
}
请注意,我已经用require_once()将所有相关文件包含到各个页面;如果我删除了有效的_image(),并在没有它的情况下运行脚本,它就可以很好地工作,但是如果我尝试设置触发错误的条件,它就不起作用,因为我尝试用精确的维度上载文件。但它仍然拒绝进入其他状态。
我在这里一片空白,这是不是做错了。如果是,那么如何将用户限制为固定的图像尺寸。任何类型的帮助都是非常感谢让我知道你采取和经验使用upmodify相关的触发错误。
提前谢谢。。