0

我有一个要在 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 函数。我必须将图像放在 adiv中,并且图像必须可调整大小:

 <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>

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

控制台中没有显示错误。

4

0 回答 0