2017 © Pedro Peláez
 

component helper

hnrHelper main objective is especially for uploading and retrieving your uploaded files (images or documents) outside yii web directory for security reason.

image

hnr/helper

hnrHelper main objective is especially for uploading and retrieving your uploaded files (images or documents) outside yii web directory for security reason.

  • Thursday, March 17, 2016
  • by rabbasa
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

HNR Helper

File Uploader, (*1)

Tujuannya adalah untuk menyimpan file uploadan di luar folder web di Yii, kemudian orang dapat mengaksesnya melalui url dengan memasukkan id dan nama file yang di-request, (*2)

informasi dari file yang diupload disimpan di dalam database dengan informasi : - id - filename - filename_real - size - content_type - created_at - updated_at - id tambahan untuk referensi misalnya : id_publikasi, id_member, id_blog, dsb, (*3)

file migrasi untuk create tabel:, (*4)

    $this->createTable('t_media_file', [
        'id'            => $this->primaryKey(),
        'id_member'     => $this->integer()->notNull(),
        'album_type'    => $this->smallInteger(1), //PROFIL,OTHER
        'is_main'       => $this->smallInteger(1)->defaultValue(0),
        'filename'      => $this->string(230), // image or cover photo
        'filename_real' => $this->string(250),
        'size'          => $this->integer()->defaultValue(0),
        'content_type'  => $this->string(75),
        'created_at'    => 'integer' ,
        'updated_at'    => 'integer' ,
    ]);

misal upload diletakkan di D:/UPLOAD (kalau windows), atau _FILES di luar folder web di Yii, (*5)

script ada di C:/htdocs/app1/backend/web, (*6)

url http://localhost/app1, (*7)

url file gambar : http://localhost/app1/media/img/9/200/400/1/namafile.jpg, (*8)

url file pdf : http://localhost/app1/media/doc/19/namadoc.pdf untuk kasus pdf, dibuat controller : - nama kontroller : MediaController - nanti ada action : actionDoc($id,$name) yang menerima parameter id : 19, nama file di database : namadoc.pdf tujuan dari namadoc.pdf adalah untuk memvalidasi, apakah record dengan id 19 nama nya sama dengan namadoc.pdf agar tidak ada orang yang mengarang2 menginput id 20, 21, dst, (*9)

contoh url Mapper :, (*10)

        'rules' => array(
                'media/img/<id:\d+>/<w>/<h>/<crop>/<nama>'  => 'media/img',
                'media/doc/<id:\d+>/<nama>'                 => 'media/doc',
                '<controller:[\w\-]+>/<action:[\w\-]+>/<id:\d+>/<name>' => '<controller>/<action>',
                '<controller:[\w\-]+>/<action:[\w\-]+>/<id:\d+>'         => '<controller>/<action>',
                '<controller:[\w\-]+>/<action:[\w\-]+>'                  => '<controller>/<action>',

http://localhost/app1/media/doc?id=19&name=namadoc.pdf, (*11)

$get=\yii::$app->request->get(); $get['id'] $get['name'], (*12)

File-file yang diletakkan di file system sebaiknya direname dengan menghilangkan spasi, koma, kurung, dsb, diganti dengan _ atau -, (*13)

The Versions

17/03 2016

dev-master

9999999-dev https://github.com/rabbasa/hnrHelper#readme

hnrHelper main objective is especially for uploading and retrieving your uploaded files (images or documents) outside yii web directory for security reason.

  Sources   Download

MIT

The Requires

 

by Harris Rabbasa

upload image resize image yii2 helper secure folder upload doc secure rename