【问题标题】:Using Uploadify with Codeigniter framework将 Uploadify 与 Codeigniter 框架一起使用
【发布时间】:2012-03-01 22:13:59
【问题描述】:

我正在尝试将 Uploadify v2.1.4 与 Codeigniter v2.1 一起使用。我知道 Flash 没有将会话数据发送到控制器存在问题,该控制器使用 codeigniter 返回 http 302 错误而不是上传脚本。

我已经看到了各种解决方案,但它们都适用于旧版本的框架,尤其是 codeigniter。有没有人找到将uploadify 与CI 集成的最新解决方案?我可以通过将上传脚本放在 CI 目录之外来使脚本工作,但我想利用 CI 功能,所以这对我来说不是一个好的解决方案。

确认我收到的错误消息是“HTTP 302”...即uploadify 脚本被禁止访问/a/reports/uploadify

这是jquery

$(document).ready(function() {
  $('#file_upload').uploadify({
    'uploader'  : '/swf/uploadify.swf',
    'script'    : '/a/reports/uploadify',
    'cancelImg' : '/img/cancel.png',
    'folder'    : '/uploads/originals', 
    'auto'      : true,
    'fileExt'   : '*.jpg;*.pdf;*.doc',
    'fileDesc'  : 'jpg, pdf or doc',
    'hideButton': false,
    'removeCompleted':false
  });

任何我的控制器

class Reports extends MY_Controller
{
public function uploadify()
{
    log_message('info','uploadify method being called');

    if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
    $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];

    log_message('info', 'File Upload: Temp file created '.$tempFile);
    log_message('info', 'File Upload: Target path for upload '.$targetPath);
    log_message('info', 'File Upload: Target file for upload '.$targetFile);

    $fileTypes  = str_replace('*.','',$_REQUEST['fileext']);
    $fileTypes  = str_replace(';','|',$fileTypes);
    $typesArray = split('\|',$fileTypes);
    $fileParts  = pathinfo($_FILES['Filedata']['name']);

    if (in_array($fileParts['extension'],$typesArray))
    {       
        move_uploaded_file($tempFile,$targetFile);
        echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
    }
    else 
    {
        log_message('error', 'File Upload: Invalid file type uploaded ['.$fileParts['extension'].']');
        echo 'Invalid file type.';
    }
    }
}
}

【问题讨论】:

    标签: codeigniter uploadify codeigniter-2


    【解决方案1】:

    最后我找到了这个解决方案。不是最好的,但仍然是一个很好的解决方法。

    http://ellislab.com/forums/viewthread/150550/

    【讨论】:

      猜你喜欢
      • 2011-09-24
      • 2017-04-26
      • 2012-01-07
      • 1970-01-01
      • 1970-01-01
      • 2016-06-17
      • 2010-11-22
      • 2023-03-18
      • 1970-01-01
      相关资源
      最近更新 更多