【问题标题】:jQuery - FileUpload plugin - PHP UploadHandlerjQuery - FileUpload 插件 - PHP UploadHandler
【发布时间】:2014-03-28 22:55:53
【问题描述】:

我设置了 jQuery FileUpload(基本版本见此处http://blueimp.github.io/jQuery-File-Upload/basic.html),并将我的文件上传到server/php/files 目录就好了。

对于常规的input type="file",我使用了以下代码:

    // if there's an CV already and no file was submitted
    if ($_POST['cv_id'] && !$_FILES['file']['tmp_name']) {
        // set current CV and job offer reply relationship
        $module_name = 'Documents';
        $link_field_name = 'hrjob_jobofferreplies_documents';
        $sugar->set_relationship($module_name, $_POST['cv_id'], $link_field_name, $job_offer_reply_id['id']);

    }

    // if a file was submitted and there's another CV already
    if ($_POST['cv_id'] && $_FILES['file']['tmp_name']) {
        // set status of old CV to inactive
        $values = array(
            'id' => $_POST['cv_id'],
            'status_id' => 'Expired'
        );
        $sugar->set('Documents', $values);

    }


// if CV was submitted
if ($_FILES['file']['tmp_name']) {
        $handle = fopen($_FILES['file']['tmp_name'], "rb");
        $filename = $_FILES['file']['name'];
        $contents = fread($handle, filesize($_FILES['file']['tmp_name']));
        $binary = base64_encode($contents);

        // create document in SugarCRM
        $values = array(
             'filename' => $filename,
             "document_name" => "Job Offer Reply",
             'category_id' => 'Resume',
             'status_id' => 'Active'
        );

        $doc_id = $sugar->set('Documents',$values);

        // create revision no. 1 to actually upload the document
        $sugar->set_document_revision($doc_id['id'],1,$binary,$filename);

    }

此代码位于自定义 Wordpress 插件的函数中。

使用 jQuery FileUpload 插件的正确方法是什么?我应该以某种方式调用此代码,还是应该使用 UploadHandler 类?

【问题讨论】:

    标签: php jquery wordpress file-upload


    【解决方案1】:

    你必须保持一切(如果不是 SugarCRM 和 WP 之间的桥梁)将会被打破。 要使用 Jquery 上传,您需要删除上传调用:

    $sugar->set_document_revision($doc_id['id'],1,$binary,$filename);
    

    在 Jquery 上传中声明 var cv_id。 检查方法 set_document_revision 也

    【讨论】:

    • 我的意思是,如何从 FileUpload 访问上传的文件?通常调用server/php/index.php,所以我想我要么需要扩展UploadHandler对象,要么以某种方式直接调用我的函数......?
    • set_document_revision 保存文件,因此如果您希望 FileUpload 执行此操作,则必须从糖方法中保存文件。 (最好的方式仍然是你自己的 WP 插件,使用 FileUpload 而不修改 Sugar)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-24
    • 2014-04-22
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    • 2014-02-03
    • 1970-01-01
    相关资源
    最近更新 更多