簡體   English   中英

jQuery Blueimp上傳插件的自定義$ options目錄?

[英]Custom $options directory for jQuery Blueimp Upload Plugin?

我一直在使用blueimp jQuery文件上傳插件 ,我正在嘗試設置用戶可以更改上傳的自定義字段。

在PHP類中,有一個構造設置所有默認選項變量。 我正在尋找可存儲此數據的最佳方式,因此在用戶設置值后,它將另存為新的默認上傳文件夾。 我正在考慮將外部XML文件導入到PHP腳本中。

這是上傳類構造函數:

    function __construct($options=null) {
    $this->options = array(
        'script_url' => $this->getFullUrl().'/',
        'upload_dir' => dirname($_SERVER['SCRIPT_FILENAME']).'/files/',

我希望這是有道理的,我很樂意澄清任何事情。 但基本上 - 我如何允許用戶手動輸入目錄結構,並成為圖像的新上傳目錄? 我在哪里可以保存這個新的字符串變量? 可能不在PHP內部,但可能在外部文件中,如XML或JSON?

我注意到你和我幾乎在同一時間在github上發布了一個blueimp上傳問題。 我不確定我有完整的答案,但是讓我告訴你到目前為止我找到的答案。 也許它會有所幫助:

我一直在尋找一種方法來過濾用戶在經過身份驗證的系統中上傳的文件。 我發布了github.com/blueimp/jQuery-File-Upload/issues/1578。 插件作者建議我在服務器端進行過濾。 我找到了github.com/blueimp/jQuery-File-Upload/issues/1149,它解釋了如何在服務器端進行過濾。 我做到了這一點,它的工作就上傳而言。 我現在已經設置了每個用戶在上傳文件夾中有一個名為其唯一ID號的子文件夾,其中包含其圖像。 所以無論如何,這是一種設置上傳路徑的動態方式。 也許你可以使用它。

我目前的問題是,盡管我可以確認圖像已上傳,但它們在下載表中不可見。 請參閱github.com/blueimp/jQuery-File-Upload/issues/1587。

我嘗試修復此問題的一次嘗試包括嘗試將選項傳遞給構造函數:

這是我在blueimp index.php文件中的代碼:

$customer_path_files = dirname($_SERVER['SCRIPT_FILENAME']) .     DIRECTORY_SEPARATOR.         'files' . DIRECTORY_SEPARATOR . $uid . DIRECTORY_SEPARATOR;
    if (!file_exists($customer_path_files)) {
    @mkdir($customer_path_files);
}
$customer_path_thumbnails = dirname($_SERVER['SCRIPT_FILENAME']) . DIRECTORY_SEPARATOR     . 'thumbnails' . DIRECTORY_SEPARATOR . $uid . DIRECTORY_SEPARATOR;
if (!file_exists($customer_path_thumbnails)) {
    @mkdir($customer_path_thumbnails);
}

$options=array(
'upload_dir' => $customer_path_files,
'upload_url' => base_url().'blueimp/server/php/files/'.$uid.'/',
'thumbnail' => array(
                'upload_dir' => $customer_path_thumbnails,
                'upload_url' => base_url().'blueimp/server/php/thumbnails/'.$uid.'/',
                'max_width' => 80,
                'max_height' => 80
            )
);


require('upload.class.php');

$upload_handler = new uploadHandler($options);

希望這里有所幫助,


附錄:

我希望如此。 BTW我讀過Jquery File Upload插件:動態更改上傳路徑? 正是我想要做的。 如果你也是,我只想說我也嘗試將會話變量(在我的情況下是一個隱藏字段中的codeigniter變體($ this-> session-> userdata('uid'))傳遞給插件的索引。 php文件,但就像在帖子中一樣,它在index.php中不存在(我想因為上傳按鈕沒有被推送用於重新填充或刪除)。這是我第一次使用ajax,但我認為會話ID必須以某種方式通過Json發送。我正在試圖解決這個問題。聽起來就像Chris G所做的那樣。如果有任何幫助我會發布以下問題並提供更多細節:

http://www.dynamicdrive.com/forums/showthread.php?p=279824

我的wordpress用戶數據代碼,

之前:

function __construct($options = null, $initialize = true) {

    $this->options = array(
        'script_url' => $this->get_full_url().'/',
        'upload_dir' => dirname($_SERVER['SCRIPT_FILENAME']).'/files/',
        'upload_url' => $this->get_full_url().'/files/',
        'user_dirs' => false,
        'mkdir_mode' => 0755,
        'param_name' => 'files',

后:

function __construct($options = null, $initialize = true) {

    require_once '../../../../wp-config.php';
    global $wpdb, $user_ID;

        if($user_ID) $userdi = $user_ID.'/';

    $this->options = array(
        'script_url' => $this->get_full_url().'/',
        'upload_dir' => dirname($_SERVER['SCRIPT_FILENAME']).'/files/'.$userdi,
        'upload_url' => $this->get_full_url().'/files/'.$userdi,
        'user_dirs' => false,
        'mkdir_mode' => 0755,
        'param_name' => 'files',

幾條評論 -

這些帖子是2012/13年度的。 更高版本的jQuery File Upload有一個選項'user_dirs'=> true,它將用戶標識符插入到存儲文件的路徑中:(來自UploadHander.php)

protected function get_upload_path($file_name = null, $version = null) {
    ...
    return $this->options['upload_dir'].$this->get_user_path().$file_name;
}

其中get_user_path返回空字符串,除非user_dirs為true。

您可以將選項傳遞給UploadHandler構造函數 - 而不是使用您的首選選項重寫UploadHander.php - 在server / php / index.php中,替換

$uploadHandler = new UploadHandler();

$uploadHandler = new UploadHandler(array('option1' => value,
                                         'option2' => value));

暫無
暫無

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

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