未捕获的异常:在uploadify与codeigniter的集成中调用StartUpload失败

时间:2013-07-26 12:28:23

标签: codeigniter

我已经将uploadify与codeigniter.i集成在一起,无法在点击所选照片时选择图像。

我的观看文件

<!DOCTYPE HTML>
<html lang="en-GB">
<head>
    <meta charset="UTF-8">
    <title>Uploadify V3 &amp; CodeIgniter</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Capsone-System2" >

    <!-- Styles -->
    <link href="/assets/bootstrap/css/bootstrap.min.css" type="text/css" media="screen" rel="stylesheet"/>
    <link href="<?php echo base_url;?>assets/js/jquery/uploadify_31/uploadify.css" type="text/css" media="screen" rel="stylesheet"/>

    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

</head>
<body>

<!-- Main Content -->
<div class="container">
    <h1 class="page-header">Uploadify V3 &amp; CodeIgniter</h1>

    <p>This is a simple tutorial demo showing Uploadify V3 working with CodeIgniter 2.1.2</p>
    <?php echo form_open_multipart(); ?>
    <ul class="unstyled">
        <li>
            <?php echo form_upload('userfile','','id="userfile"'); ?>
            <?php echo (isset($error)) ? $error : ''; ?>
        </li>
        <li>
            <?php echo form_button(array('content'=> 'Upload', 'id'=>'upload-file', 'class'=>'btn btn-large btn-primary')); ?>
        </li>
    </ul>
    <?php echo form_close(); ?>
</div>
<!-- End Of Main Content -->

<!--<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>-->
<!--<script>window.jQuery || document.write('<script src="<?php echo base_url;?>assets/js/jquery/jquery-1.8.0.min.js"></script>')</script>-->
<script src="<?php echo base_url;?>assets/js/jquery/uploadify_31/jquery.uploadify-3.1.min.js" type="text/javascript"></script>
<!--<script src="<?php echo base_url;?>assets/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>-->
<script type="text/javascript">
    $(document).ready(function () {

        var base_url = '<?php echo base_url; ?>';
        alert(base_url);

        $('#upload-file').click(function (e) {
            e.preventDefault();
            $('#userfile').uploadify('upload', '*');
            alert(base_url);
        });

        $('#userfile').uploadify({

            'debug':true,
            'auto':false,
            'swf': base_url + 'assets/js/jquery/uploadify_31/uploadify.swf',
            'uploader': base_url + 'uploadify_v3/do_upload',
            'cancelImg': base_url + 'assets/javascript/jquery/uploadify_31/uploadify-cancel.png',
            'fileTypeExts':'*.jpg;*.bmp;*.png;*.tif',
            'fileTypeDesc':'Image Files (.jpg,.bmp,.png,.tif)',
            'fileSizeLimit':'2MB',
            'fileObjName':'userfile',
            'buttonText':'Select Photo(s)',
            'multi':true,
            'removeCompleted':false,
            'onUploadError' : function(file, errorCode, errorMsg, errorString) {
                alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
            }
        });
    });
</script>
</body>
</html>

我的控制器文件

我有错误未捕获异常:调用StartUpload失败

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @property CI_Upload $upload
 */

class Uploadify_v3 extends CI_Controller
{

    public $view_data = array();
    private $upload_config;

    function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $this->load->helper(array('url', 'form'));
        $this->load->view('uploadify_v3', $this->view_data);
    }

    public function do_upload()
    {
        $this->load->library('upload');

        $image_upload_folder = FCPATH . '/uploads';

        if (!file_exists($image_upload_folder)) {
            mkdir($image_upload_folder, DIR_WRITE_MODE, true);
        }

        $this->upload_config = array(
            'upload_path'   => $image_upload_folder,
            'allowed_types' => 'png|jpg|jpeg|bmp|tiff',
            'max_size'      => 2048,
            'remove_space'  => TRUE,
            'encrypt_name'  => TRUE,
        );

        $this->upload->initialize($this->upload_config);

        if (!$this->upload->do_upload()) {
            $upload_error = $this->upload->display_errors();
            echo json_encode($upload_error);
        } else {
            $file_info = $this->upload->data();
            echo json_encode($file_info);
        }

    }

}

/* End of file uploadify_v3.php */
/* Location: ./application/controllers/uploadify_v3.php */

我花了更多时间..现在我无法解决这个错误..请帮助我。

1 个答案:

答案 0 :(得分:0)

我也有同样的问题,这是一个安全问题,因为我在一个单独的域上托管flash .swf文件,例如:static.mysite.com

确保您的swf文件和帖子处理程序脚本托管在您访问该网站的同一域中。

或者,如果您需要添加跨域发布,请参阅此处:

http://www.adobe.com/devnet/adobe-media-server/articles/cross-domain-xml-for-streaming.html