3

Yiiは初めてで、ファイルのアップロードを統合したいと思っています。残念ながら、それを機能させることができませんでした。プラグインをダウンロードして/ extends /フォルダーに解凍しましたが、どうすればよいかわかりません。

誰かが私を導くことができますか?

ここに拡張機能のリンクがあります

http://www.yiiframework.com/extension/xupload/

4

2 に答える 2

4

その拡張機能は古く、サポートが不十分です。代わりに、この拡張機能を使用します:eajaxupload

そのページでわかるように、使用法は非常に簡単です。拡張機能ディレクトリにアップロードし、これらの数行のコードでインストールします

まず、コントローラーアクションに次のコードを追加します。

public function actionUpload()
{
        Yii::import("ext.EAjaxUpload.qqFileUploader");

        $folder='upload/';// folder for uploaded files
        $allowedExtensions = array("jpg");//array("jpg","jpeg","gif","exe","mov" and etc...
        $sizeLimit = 10 * 1024 * 1024;// maximum file size in bytes
        $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
        $result = $uploader->handleUpload($folder);
        $result=htmlspecialchars(json_encode($result), ENT_NOQUOTES);

        $fileSize=filesize($folder.$result['filename']);//GETTING FILE SIZE
        $fileName=$result['filename'];//GETTING FILE NAME

        echo $result;// it's array
}

その後、そのアクションに関連付けられたビューファイルに移動し、次のコードを使用してアップロードフォームを生成します。

<? $this->widget('ext.EAjaxUpload.EAjaxUpload',
array(
        'id'=>'uploadFile',
        'config'=>array(
               'action'=>'/controller/upload',
               'allowedExtensions'=>array("jpg");//array("jpg","jpeg","gif","exe","mov" and etc...
               'sizeLimit'=>10*1024*1024,// maximum file size in bytes
               'minSizeLimit'=>10*1024*1024,// minimum file size in bytes
               //'onComplete'=>"js:function(id, fileName, responseJSON){ alert(fileName); }",
               //'messages'=>array(
               //                  'typeError'=>"{file} has invalid extension. Only {extensions} are allowed.",
               //                  'sizeError'=>"{file} is too large, maximum file size is {sizeLimit}.",
               //                  'minSizeError'=>"{file} is too small, minimum file size is {minSizeLimit}.",
               //                  'emptyError'=>"{file} is empty, please select files again without it.",
               //                  'onLeave'=>"The files are being uploaded, if you leave now the upload will be cancelled."
               //                 ),
               //'showMessage'=>"js:function(message){ alert(message); }"
              )
)); ?>

非常に簡単に作業できます。試してごらん!

于 2011-12-17T10:01:28.903 に答える
-1

画像を保存する前にファイル名を変更するには、コメント行のコメントを外し、選択した名前を入力します。

./extensions/EAjaxUpload/qqFileUploader.php

    $pathinfo = pathinfo($this->file->getName());
    $filename = $pathinfo['filename'];
    //$filename = md5(uniqid());
    $ext = $pathinfo['extension'];
于 2016-07-11T22:52:21.490 に答える