PHP code example of moln / gzfextra

1. Go to this page and download the library: Download moln/gzfextra library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

moln / gzfextra example snippets


return array(
    'service_manager'    => array(
        'abstract_factories' => array(
            'Gzfextra\Db\TableGateway\TableGatewayAbstractServiceFactory',
        ),
    ),
    'tables' => array(
        'UserTable'  => array(
            'table'     => 'users',
            'invokable' => 'User\\Model\\UserTable',
            'primary'   => 'user_id',
        ),
        'RoleTable' => array(
            'table'     => 'roles',
            'invokable' => 'User\\Model\\RoleTable',
            'primary'   => 'role_id',
        ),
    ),
);

namespace User\Model;
use Zend\Db\TableGateway\TableGateway as ZendTableGateway;

/**
 * UserTable
 *
 * 默认带有公共函数特性
 * @method int fetchCount($where)
 * @method \ArrayObject|\Zend\Db\RowGateway\RowGateway find($id)
 * @method \Zend\Paginator\Paginator fetchPaginator($where = null)
 * @method int deletePrimary($key)
 */
class UserTable extends ZendTableGateway
{
}

public function indexAction()
{
    $users = $this->getServiceLocator()->get('UserTable');
    $row = $users->find(1);
}

class Module
{
    public function onBootstrap(MvcEvent $e)
    {
        $eventManager = $e->getApplication()->getEventManager();

        $gListener = new GlobalModuleRouteListener();
        $eventManager->attach($gListener);
    }

    public function getConfig()
    {
        return GlobalModuleRouteListener::getDefaultRouterConfig();
    }
}

return array(
    'service_manager' => array(
        'factories' => array(
            'FileStorage' => '\Gzfextra\FileStorage\StorageFactory'
        )
    ),
    'file_storage'    => array(
        'type'    => 'fileSystem',
        'options' => array(
            'default_path' => realpath('./public/uploads'),
            'validators'   => array(
                'Extension' => array('gif', 'jpg', 'jpeg', 'png'),
                'Size'      => array('max' => 1024 * 1024),
                'IsImage',
            ),
            'filters'      => array(
                'LowerCaseName',
                'RenameUpload' => array(
                    'target'               => 'shop',
                    'use_upload_extension' => true,
                    'randomize'            => true,
                ),
            ),
        ),
    ),
);

return array(
    'service_manager' => array(
        'abstract_factories' => array(
            '\Gzfextra\FileStorage\StorageAbstractFactory'
        ),
    ),
    'file_storage_configs' => array(
        'ImageFileStorage'    => array(
            'type'    => 'fileSystem',
            'options' => array(
                'default_path' => realpath('./public/uploads'),
                'validators'   => array(
                    'Extension' => array('gif', 'jpg', 'jpeg', 'png'),
                    'Size'      => array('max' => 1024 * 1024),
                    'IsImage',
                ),
                'filters'      => array(
                    'LowerCaseName',
                    'RenameUpload' => array(
                        'target'               => 'shop',
                        'use_upload_extension' => true,
                        'randomize'            => true,
                    ),
                ),
            ),
        ),
        'ZipFileStorage'    => array(
            'type'    => 'ftp',
            'options' => array(
                'ftp' => array(
                    'host' => 'localhost',
                    'username' => 'ftpuser',
                    'password' => '123456',
                    'pasv' => true,
                ),
                'default_path' => '/',
                'validators'   => array(
                    'Extension' => array('zip'),
                ),
                'filters'      => array(
                    'LowerCaseName',
                    'RenameUpload' => array(
                        'target'               => 'zipfile',
                        'use_upload_extension' => true,
                        'randomize'            => true,
                    ),
                ),
            ),
        ),
    ),
);

public function indexAction()
{
    $fileStorage = $this->getServiceLocator()->get('ImageFileStorage');
    if ($fileStorage->isValid()) {
        $file = $fileStorage->upload($file);
        // var_dump($file);
    }
}