Download the PHP package josegonzalez/cakephp-upload-with-rename without Composer

On this page you can find all versions of the php package josegonzalez/cakephp-upload-with-rename. 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 cakephp-upload-with-rename

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:

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 Clone]

In your Plugin directory type:

Imagick Support

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

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:

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

Usage

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:

In the above example, photo can be a file upload via a file input within a form, a file grabber (from a url) via a text input, OR programatically used on the controller to file grab via a url.

File Upload Example

File Grabbing via Form Example

Programmatic File Retrieval without a Form

Thumbnail Creation

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'.

Uploading Multiple files

Multiple files can also be attached to a single record:

Each key in the Upload.Upload array is a field name, and can contain it's own configuration. For example, you might want to set different fields for storing file paths:

Keep in mind that while this plugin does not have any limits in terms of number of files uploaded per request, you should keep this down in order to decrease the ability of your users to block other requests.

PDF Support

It is now possible to generate a thumbnail for the first page of a PDF file. (Only works with the imagick thumbnailMethod.)

Please read about the Behavior options for more details as to how to configure this plugin.

Using a Polymorphic Attachment Model for File Storage

In some cases you will want to store multiple file uploads for a multiple models, but will not want to use multiple tables for some reason. For example, we might have a Post model that can have many images for a gallery, and a Message model that has many videos. In this case, we would use an Attachment model:

Post hasMany Attachment

We could use the following database schema for the Attachment model:

Our attachment records would thus be able to have a name and be activated/de-activated on the fly. The schema is simply an example, and such functionality would need to be implemented within your application.

Once the attachments table has been created, we would create the following model:

We would also need to present a valid counter-relationship in the Post model:

The key thing to note here is the Post model has some conditions on the relationship to the Attachment model, where the Image.model has to be Post. Remember to set the model field to Post, or whatever model it is you'd like to attach it to, otherwise you may get incorrect relationship results when performing find queries.

We would also need a similar relationship in our Message model:

Now that we have our models setup, we should create the proper actions in our controllers. To keep this short, we shall only document the Post model:

In the above example, we are calling our custom createWithAttachments method on the Post model. This will allow us to unify the Post creation logic together in one place. That method is outlined below:

The above model method will:

Now that this is set, we just need a view for our controller. A sample view for View/Posts/add.ctp is as follows (fields not necessary for the example are omitted):

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.

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

isUnderFormSizeLimit

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

isCompletedUpload

Check that the file was completely uploaded

isFileUpload

Check that a file was uploaded

isFileUploadOrHasExistingValue

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

tempDirExists

Check that the PHP temporary directory is missing

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

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

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

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

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

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

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

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

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

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

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

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)

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

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)

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

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

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

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)

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

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)

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

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)

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

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)

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

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:

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 cakephp-upload-with-rename 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 josegonzalez/cakephp-upload-with-rename contains the following files

Loading the files please wait ....