PHP图像调整大小

I am using Uploadify and class.upload.php for uploading and manipulating images. here are my code.

require_once('/style/scripts/crop/class.upload.php');
    if (!empty($_FILES)) {
         $uc = $this->input->post('username');
         $_REQUEST['folder'] = "/project/user/".$uc."/pages".$_REQUEST['folder']."/images/gallery";
        $targetPath = $_SERVER['DOCUMENT_ROOT'] .$_REQUEST['folder']. '/';
        $pic_temp = random_string('alnum',10);
        $handle = new Upload($_FILES['Filedata']);
            if ($handle->uploaded) {
                $handle->file_src_name_body      = $pic_temp; // hard name
                $handle->file_overwrite          = true;
                $handle->file_auto_rename        = false;
                $handle->image_resize            = false;
                $handle->image_ratio_y           = false;
                $handle->image_x                 = ($handle->image_src_x < 400)?$handle->image_src_x:400;
                $handle->file_max_size           = '999999'; // max size
                $handle->Process($targetPath);
                $handle->clean(); 
                if ($handle->processed)
                    $json = array("result"      => 1, 
                                  "file"        => $_REQUEST['folder'].'/'.$handle->file_dst_name.'?'.time(),
                                  "imagewidth"  => $handle->image_dst_x,
                                  "imageheight" => $handle->image_dst_y
                                 );
                else
                    $json = array("result" => 0);

                $encoded = json_encode($json);
                echo $encoded;
                unset($encoded);    
            } 
            else { 
                $json = array("result" => 0);
                $encoded = json_encode($json);
                echo $encoded;
                unset($encoded);
            }

Now i want to check the file size before upload, if a image with more than 1MB in size then it should be re-sized [No cropping or other things...] to save Disk space. if it is less then 1MB it should be uploaded directly.

How can i achieve this ?

The project is doing with Codeigniter framework.

When a file is uploaded, you can access it at:

$_FILES['some_name']['tmp_name']

So to check it's size, you could do something like:

$size = filesize($_FILES['some_name']['tmp_name']);

See the documentation on filesize for more information.

$(document).ready(function() {
    $('#id_image').bind('change', function() {
        if(this.files[0].size > 1000141){
            $('#formerror').html('File is too big');
            $('#myformbutton').hide();
        }else{
            $('#formerror').html(' ');
            $('#myformbutton').show('slow');
        }
    });
});

    <div id="formerror"></div>
    <form action="myaction" method="post" id="myform" enctype="multipart/form-data">
         <label for="id_title">Title</label>
         <input id="id_title" type="text" name="title" maxlength="255" />
         <label for="id_image">Image</label>
         <input type="file" name="image" id="id_image" />
         <input type="button" id="myformbutton" value="Add!" />
    </form>

Uploadify has a parameter to limit file size: sizeLimit. If that's set, it will prevent the file from being submitted.

http://www.uploadify.com/documentation/options/sizelimit/

Most (if not all) of the flash based uploaders like swf, solmetra, etc allow you to check file size prior to upload. Also, you can technically resize the file yourself on the server too but that does waste your bandwidth.