Help me understand the logic behind Uploading the file using Uploadify

TungN

New Member
I am using Uploadify to Upload the Images. the only glitch i am facing is i want to restrict the image dimension to the user for uploading the image. (I do not want to use the image resize for some reason). my logic for doing that in php is i have a user defined function which will take three parameters first the image tempname, second the width of the image to restrict, third the height of the image to restrict the user.my function is something like this.\[code\]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; }\[/code\]i want to apply the same rule for uploadify. here is my Jquery Script for Uploadify.\[code\]//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(); } }); }); \[/code\]now i want uploadify to generate the error if it does not satisfy the condition for that in uploadify.php i did something like this.\[code\]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"; }}\[/code\]Please Note that i have included all related file to the respective pages with require_once(); if i remove that valid_image() and run the script without it it just work perfectly fine, but if i try to put on a condition to trigger the error it does not work because i tried uploading the file with exact dimension. and still it refuses to enter that else condition. i am going blank here, is this the wrong way of doing it. if yes then how do i restrict the user to fixed image dimension. any type of help is highly appreciated let me know your take and experience using Uplodify related to triggering the error.thanks in advance..
 
Back
Top