Download the PHP package simkimsia/upload without Composer

On this page you can find all versions of the php package simkimsia/upload. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package upload

Build Status Coverage Status Total Downloads Latest Stable Version

Upload Plugin 2.0

The Upload Plugin is an attempt to sanely upload files using techniques garnered packages such as MeioUpload , UploadPack and PHP documentation.

Background

Media Plugin is too complicated, and it was a PITA to merge the latest updates into MeioUpload, so here I am, building yet another upload plugin. I'll build another in a month and call it "YAUP".

Requirements

Installation

[Using Composer]

View on Packagist, and copy the json snippet for the latest version into your project's composer.json. Eg, v. 1.0.0 would look like this:

{
    "require": {
        "josegonzalez/cakephp-upload": "1.0.0"
    }
}

Because this plugin has the type cakephp-plugin set in it's own composer.json, composer knows to install it inside your /Plugins directory, rather than in the usual vendors file. It is recommended that you add /Plugins/Upload to your .gitignore file. (Why? read this.)

[Manual]

[GIT Submodule]

In your app directory type:

git submodule add -b master git://github.com/josegonzalez/cakephp-upload.git Plugin/Upload
git submodule init
git submodule update

[GIT Clone]

In your Plugin directory type:

git clone -b master git://github.com/josegonzalez/cakephp-upload.git Upload

Imagick Support

To enable Imagick support, you need to have imagick installed:

# Debian systems
sudo apt-get install php-imagick

# OS X Homebrew
brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
brew install php54-imagick

# From pecl
pecl install imagick

If you cannot install imagick, please do not use imagick, and instead configure the plugin with 'thumbnailMethod' => 'php' in your setup options.

Enable plugin

In 2.0 you need to enable the plugin your app/Config/bootstrap.php file:

CakePlugin::load('Upload');

If you are already using CakePlugin::loadAll();, then this is not necessary.

Usage

CREATE table users (
    id int(10) unsigned NOT NULL auto_increment,
    username varchar(20) NOT NULL,
    photo varchar(255)
);

Using the above setup, uploaded files cannot be deleted. To do so, a field must be added to store the directory of the file as follows:

CREATE table users (
    `id` int(10) unsigned NOT NULL auto_increment,
    `username` varchar(20) NOT NULL,
    `photo` varchar(255) DEFAULT NULL,
    `photo_dir` varchar(255) DEFAULT NULL,
    PRIMARY KEY (`id`)
);

File Grabbing via Form Example

Programmatic File Grab via Controller

$data['photo'] = $image_url;
$this->User->set($data);
$this->User->save();

Thumbnails are not automatically created. To do so, thumbnail sizes must be defined: Note: by default thumbnails will be generated by imagick, if you want to use GD you need to set the thumbnailMethod attribute. Example: 'thumbnailMethod' => 'php'.

The one important thing you'll notice is that I am not referring to the Attachment model as Attachment, but rather as Image; when I initially specified the $hasMany relationship between an Attachment and a Post, I aliased Attachment to Image. This is necessary for cases where many of your Polymorphic models may be related to each other, as a type of hint to the CakePHP ORM to properly reference model data.

I'm also using Model.{n}.field notation, which would allow you to add multiple attachment records to the Post. This is necessary for $hasMany relationships, which we are using for this example.

Once you have all the above in place, you'll have a working Polymorphic upload!

Please note that this is not the only way to represent file uploads, but it is documented here for reference.

Alternative Behaviors

The Upload plugin also comes with a FileImport behavior and a FileGrabber behavior.

FileImportBehavior

FileImportBehavior may be used to import files directly from the disk. This is useful in importing from a directory already on the filesystem.

Behavior options:

Thumbnail Sizes and Styles

Styles are the definition of thumbnails that will be generated for original image. You can define as many as you want.

<?php
class User extends AppModel {
    public $name = 'User';
    public $actsAs = array(
        'Upload.Upload' => array(
            'photo' => array(
                'thumbnailSizes' => array(
                    'big' => '200x200',
                    'small' => '120x120'
                    'thumb' => '80x80'
                )
            )
        )
    );
}

Styles only apply to images of the following types:

You can specify any of the following resize modes for your sizes:

Validation rules

By default, no validation rules are attached to the model. One must explicitly attach each rule if needed. Rules not referring to PHP upload errors are configurable but fallback to the behavior configuration.

isUnderPhpSizeLimit

Check that the file does not exceed the max file size specified by PHP

public $validate = array(
    'photo' => array(
        'rule' => 'isUnderPhpSizeLimit',
        'message' => 'File exceeds upload filesize limit'
    )
);

isUnderFormSizeLimit

Check that the file does not exceed the max file size specified in the HTML Form

public $validate = array(
    'photo' => array(
        'rule' => 'isUnderFormSizeLimit',
        'message' => 'File exceeds form upload filesize limit'
    )
);

isCompletedUpload

Check that the file was completely uploaded

public $validate = array(
    'photo' => array(
        'rule' => 'isCompletedUpload',
        'message' => 'File was not successfully uploaded'
    )
);

isFileUpload

Check that a file was uploaded

public $validate = array(
    'photo' => array(
        'rule' => 'isFileUpload',
        'message' => 'File was missing from submission'
    )
);

isFileUploadOrHasExistingValue

Check that either a file was uploaded, or the existing value in the database is not blank

public $validate = array(
    'photo' => array(
        'rule' => 'isFileUploadOrHasExistingValue',
        'message' => 'File was missing from submission'
    )
);

tempDirExists

Check that the PHP temporary directory is missing

public $validate = array(
    'photo' => array(
        'rule' => 'tempDirExists',
        'message' => 'The system temporary directory is missing'
    )
);

If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:

public $validate = array(
    'photo' => array(
        'rule' => array('tempDirExists', false),
        'message' => 'The system temporary directory is missing'
    )
);

In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.

isSuccessfulWrite

Check that the file was successfully written to the server

public $validate = array(
    'photo' => array(
        'rule' => 'isSuccessfulWrite',
        'message' => 'File was unsuccessfully written to the server'
    )
);

If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:

public $validate = array(
    'photo' => array(
        'rule' => array('isSuccessfulWrite', false),
        'message' => 'File was unsuccessfully written to the server'
    )
);

In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.

noPhpExtensionErrors

Check that a PHP extension did not cause an error

public $validate = array(
    'photo' => array(
        'rule' => 'noPhpExtensionErrors',
        'message' => 'File was not uploaded because of a faulty PHP extension'
    )
);

If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:

public $validate = array(
    'photo' => array(
        'rule' => array('noPhpExtensionErrors', 1024, false),
        'message' => 'File was not uploaded because of a faulty PHP extension'
    )
);

In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.

isValidMimeType

Check that the file is of a valid mimetype

public $validate = array(
    'photo' => array(
        'rule' => array('isValidMimeType', array('application/pdf', 'image/png')),
        'message' => 'File is not a pdf or png'
    )
);

If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:

public $validate = array(
    'photo' => array(
        'rule' => array('isValidMimeType', array('application/pdf', 'image/png'), false),
        'message' => 'File is not a pdf or png'
    )
);

In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.

isWritable

Check that the upload directory is writable

public $validate = array(
    'photo' => array(
        'rule' => array('isWritable'),
        'message' => 'File upload directory was not writable'
    )
);

If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:

public $validate = array(
    'photo' => array(
        'rule' => array('isWritable', false),
        'message' => 'File upload directory was not writable'
    )
);

In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.

isValidDir

Check that the upload directory exists

public $validate = array(
    'photo' => array(
        'rule' => array('isValidDir'),
        'message' => 'File upload directory does not exist'
    )
);

If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:

public $validate = array(
    'photo' => array(
        'rule' => array('isValidDir', false),
        'message' => 'File upload directory does not exist'
    )
);

In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.

isBelowMaxSize

Check that the file is below the maximum file upload size (checked in bytes)

public $validate = array(
    'photo' => array(
        'rule' => array('isBelowMaxSize', 1024),
        'message' => 'File is larger than the maximum filesize'
    )
);

If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:

public $validate = array(
    'photo' => array(
        'rule' => array('isBelowMaxSize', 1024, false),
        'message' => 'File is larger than the maximum filesize'
    )
);

In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.

isAboveMinSize

Check that the file is above the minimum file upload size (checked in bytes)

public $validate = array(
    'photo' => array(
        'rule' => array('isAboveMinSize', 1024),
        'message' => 'File is below the mimimum filesize'
    )
);

If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:

public $validate = array(
    'photo' => array(
        'rule' => array('isAboveMinSize', 1024, false),
        'message' => 'File is below the mimimum filesize'
    )
);

In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.

isValidExtension

Check that the file has a valid extension

public $validate = array(
    'photo' => array(
        'rule' => array('isValidExtension', array('pdf', 'png', 'txt')),
        'message' => 'File does not have a pdf, png, or txt extension'
    )
);

If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:

public $validate = array(
    'photo' => array(
        'rule' => array('isValidExtension', array('pdf', 'png', 'txt'), false),
        'message' => 'File does not have a pdf, png, or txt extension'
    )
);

In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.

isAboveMinHeight

Check that the file is above the minimum height requirement (checked in pixels)

public $validate = array(
    'photo' => array(
        'rule' => array('isAboveMinHeight' 150),
        'message' => 'File is below the minimum height'
    )
);

If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:

public $validate = array(
    'photo' => array(
        'rule' => array('isAboveMinHeight', 150, false),
        'message' => 'File is below the minimum height'
    )
);

In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.

isBelowMaxHeight

Check that the file is below the maximum height requirement (checked in pixels)

public $validate = array(
    'photo' => array(
        'rule' => array('isBelowMaxHeight', 150),
        'message' => 'File is above the maximum height'
    )
);

If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:

public $validate = array(
    'photo' => array(
        'rule' => array('isBelowMaxHeight', 150, false),
        'message' => 'File is above the maximum height'
    )
);

In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.

isAboveMinWidth

Check that the file is above the minimum width requirement (checked in pixels)

public $validate = array(
    'photo' => array(
        'rule' => array('isAboveMinWidth', 150),
        'message' => 'File is below the minimum width'
    )
);

If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:

public $validate = array(
    'photo' => array(
        'rule' => array('isAboveMinWidth', 150, false),
        'message' => 'File is below the minimum width'
    )
);

In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.

isBelowMaxWidth

Check that the file is below the maximum width requirement (checked in pixels) public $validate = array( 'photo' => array( 'rule' => array('isBelowMaxWidth', 150), 'message' => 'File is above the maximum width' ) );

If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:

public $validate = array(
    'photo' => array(
        'rule' => array('isBelowMaxWidth', 150, false),
        'message' => 'File is above the maximum width'
    )
);

In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.

Remove a current file without deleting the entire record

In some cases you might want to remove a photo or uploaded file without having to remove the entire record from the Model. In this case you would use the following code:

<?php
echo $this->Form->create('Model', array('type' => 'file'));
echo $this->Form->input('Model.file.remove', array('type' => 'checkbox', 'label' => 'Remove existing file'));

License

The MIT License (MIT)

Copyright (c) 2010 Jose Diaz-Gonzalez

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


All versions of upload with dependencies

PHP Build Version
Package Version
Requires composer/installers Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package simkimsia/upload contains the following files

Loading the files please wait ...