Php 帮助我理解使用Uploadify上传文件背后的逻辑
我正在使用Uploadify上传图像。我面临的唯一问题是,我想将图像尺寸限制为上传图像的用户。(由于某些原因,我不想使用图像调整大小)。我在php中这样做的逻辑是,我有一个用户定义的函数,它将接受三个参数:第一个是图像tempname,第二个是要限制的图像宽度,第三个是要限制用户的图像高度 我的函数是这样的Php 帮助我理解使用Uploadify上传文件背后的逻辑,php,jquery,Php,Jquery,我正在使用Uploadify上传图像。我面临的唯一问题是,我想将图像尺寸限制为上传图像的用户。(由于某些原因,我不想使用图像调整大小)。我在php中这样做的逻辑是,我有一个用户定义的函数,它将接受三个参数:第一个是图像tempname,第二个是要限制的图像宽度,第三个是要限制用户的图像高度 我的函数是这样的 function valid_image($image, $width, $height = 0) { /** Get the Dimensions of the
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;
}
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";
}
}
我想对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();
}
}); });
请注意,我已使用require_once()将所有相关文件包含到相应页面中;如果我删除了有效的_image()并在没有它的情况下运行脚本,它就可以正常工作,但是如果我试图设置触发错误的条件,它就不起作用,因为我尝试上载具有精确尺寸的文件。但它仍然拒绝进入其他条件
我要发呆了,这样做是不是不对。如果是,那么如何将用户限制为固定的图像尺寸。非常感谢您提供的任何类型的帮助,让我知道您使用Uplodify触发错误的方式和经验
提前感谢..更改
进入
似乎你已经工作太久了,以至于你没有抓住这个小小的错误:)似乎是我工作太久了
编辑: 在
valid_image
函数的顶部,添加:
var_dump($image, getimagesize($image['tmp_name']));
输出的是什么?您可以更改吗!==到!=在valid_image函数中,然后尝试在
www.uploadify.com
中的“uploadify”?…无论是否使用uploadify,这都适用。否:(查看我的用户定义的valid_image函数我已要求函数将参数与['tmp_name']绑定。这是代码。$image['tmp_name'];我甚至尝试过你的提示,但都不起作用。我的问题是uploadify.php能做到这一点吗?是的,从php的角度来看,这是一个完全正常的文件上传。@aularon感谢你的痛苦。:),我解决了它,我不知道出了什么问题,但我又从头开始工作了。:)
if(!valid_image($tempFile,685 , 50)) {
var_dump($image, getimagesize($image['tmp_name']));