簡體   English   中英

jQuery-FileUpload插件-PHP UploadHandler

[英]jQuery - FileUpload plugin - PHP UploadHandler

我設置了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類?

您必須保留所有內容(如果不是SugarCRM和WP之間的橋梁)將被破壞。 要使用Jquery上傳,您需要刪除上傳調用:

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

在Jquery上傳中聲明var cv_id。 還要檢查方法set_document_revision

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM