Codeigniter图像上传和调整大小- swfupload


codeigniter image upload and resize - swfupload

我目前正在编写网站的一部分,允许用户上传图像,然后选择该图像的一个区域进行裁剪。我想要它,以便图像上传,而无需用户提交表单,所以我使用一个名为swfupload的工具,我已经设法获得图像上传,但是我不能让swfupload创建一个缩略图,甚至在我的缩略图方法中读取。

下面是我的代码, PHP

public function upload()
    {
        $config['upload_path'] = "./media/uploads/users";
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '1000';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        $config['encrypt_name']  = TRUE;
        $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload('Filedata'))
        {
            $error = array('error' => $this->upload->display_errors());
            //die(print_r($error));
        }
        else
        {
            $this->file = $this->upload->data();
            echo $this->file['file_name'];
        }
    }
    public function thumbnail()
    {
                //lets just try and get thumbnail() talking to swfupload
        echo 1;
    }

swfupload js

window.onload = function () {
            swfu = new SWFUpload({
                // Backend Settings
                upload_url: "http://lcl.moovjob.com/index.php/admin/users/upload",
                post_params: {"PHPSESSID": "<?php echo $this->session->userdata('session_id'); ?>" },
                // File Upload Settings
                file_size_limit : "5 MB",   // 5MB
                file_types : "*.jpg",
                file_types_description : "JPG Images",
                file_upload_limit : "0",
                // Event Handler Settings - these functions as defined in Handlers.js
                //  The handlers are not part of SWFUpload but are part of my website and control how
                //  my website reacts to the SWFUpload events.
                file_queue_error_handler : fileQueueError,
                file_dialog_complete_handler : fileDialogComplete,
                upload_progress_handler : uploadProgress,
                upload_error_handler : uploadError,
                upload_success_handler : uploadSuccess,
                upload_complete_handler : uploadComplete,
                // Button Settings
                button_image_url : "images/SmallSpyGlassWithTransperancy_17x18.png",
                button_placeholder_id : "spanButtonPlaceholder",
                button_width: 180,
                button_height: 18,
                button_text : '<span class="button">Select Images <span class="buttonSmall">(2 MB Max)</span></span>',
                button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .buttonSmall { font-size: 10pt; }',
                button_text_top_padding: 0,
                button_text_left_padding: 18,
                button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
                button_cursor: SWFUpload.CURSOR.HAND,
                // Flash Settings
                flash_url : "/media/flash/swfupload.swf",
                custom_settings : {
                    upload_target : "divFileProgressContainer"
                },
                // Debug Settings
                debug: true
            });
        };

My Handlers js,特别是upload success方法,

function uploadSuccess(file, serverData) {
    try {
        var progress = new FileProgress(file,  this.customSettings.upload_target);
        if (serverData.substring(0, 7) === "FILEID:") {
            addImage("http://local.test.com/index.php/admin/users/thumbnail");
            progress.setStatus("Thumbnail Created.");
            progress.toggleCancel(false);
        } else {
            addImage("images/error.gif");
            progress.setStatus("Error.");
            progress.toggleCancel(false);
            alert(serverData);
        }

    } catch (ex) {
        this.debug(ex);
    }
}

我在做什么,目前所有我想要的是图像上传,然后返回1,所以我知道swfupload正在与我的控制器交谈。我得到的只是上传成功或错误。

您可以使用jquery的图像区域选择插件的jquery文件上传器。这是图片区域选择插件的URL:http://odyniec.net/projects/imgareaselect/

我有点困惑为什么你不把缩略图方法添加到你的上传函数的末尾?据我所知,没有必要分别进行这些操作。

你已经在你的上传函数中有一个成功上传的检查,所以在它返回任何数据之前,将文件名/dir传递给你的缩略图函数,创建缩略图,然后以这种方式返回成功或失败到你的js