dongyong8098 2011-11-30 09:26
浏览 42
已采纳

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.

  • 写回答

3条回答 默认 最新

  • duanfen9090 2011-11-30 21:48
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line