jQuery可在图像上调整大小

时间:2013-05-13 16:13:12

标签: php jquery jquery-ui-resizable

我有一个在CodeIgniter中开发的网站,我想用AJAX上传图片并使其可调整大小。我可以上传并显示图片,但不能调整大小。

这是我的上传脚本:

public function ajaximage(){
        $path = "uploads/tee/element/";
        $session_id = $this->session->userdata('id');

        $valid_formats = array("jpg", "png", "gif", "bmp","jpeg");
        if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
        {
            $name = $_FILES['upload']['name'];
            $size = $_FILES['upload']['size'];
        if(strlen($name))
        {
            list($txt, $ext) = explode(".", $name);
            if(in_array($ext,$valid_formats))
        {
        if($size<(1024*1024)) // Image size max 1 MB
        {
            $actual_image_name = time().$session_id.".".$ext;
            $tmp = $_FILES['upload']['tmp_name'];

            if(move_uploaded_file($tmp, $path.$actual_image_name))
            {
                echo "<img src='".base_url().$path.$actual_image_name."' class='resizable' width='200px' height='100px'>";
            }
            else
                echo "failed";
            }
            else
                echo "Image file size max 1 MB";
            }
            else
                echo "Invalid file format..";
            }
            else
                echo "Please select image..!";
            exit;
        }
    }

这是我处理请求的AJAX函数。我必须将图像放在div内,图像必须可以调整大小:

 <script>

    $(document).ready(function(){
        $(".resizable").resizable();

        function showResponse(responseText){
            $(responseText).appendTo("#space-drawable-div").resizable();
            $(responseText).css('position','absolute').css('top','0px').css('left','0px').css('z-index','5');
        }

        $('#upload-form').ajaxForm(showResponse);

    });


    </script>

显示图像,但我无法调整大小。

控制台中没有显示错误。

0 个答案:

没有答案