Giter VIP home page Giter VIP logo

transit's Introduction

Transit v2.0.0 Build Status

A lightweight file uploader that also provides extended support for file validation, file transformation (image resizing, cropping, etc) and file transportation (moving files to Amazon S3 or another external storage system).

Requirements

  • PHP 5.4
    • Fileinfo
    • Multibyte
    • Curl
    • Exif (optional)
  • Composer
    • AWS SDK (optional)
    • Rackspace OpenCloud SDK (optional)

Features

  • Easily upload a file into the local file system
  • Basic support for file moving and renaming through File
  • Overwrite protection and file name filtering
  • Import a file from a remote location, local file system path or an input stream
  • Transform and alter a file by running a Transformer on it
  • Create new files based off an original file by using transformers
  • Transport to or delete a file from Amazon S3 or Glacier using a Transporter
  • Validate files and images using a defined set of rules using a Validator
  • Support for extending built in transporters, transformers and validators
  • Exif reading support through File and orientation fixing through ExifTransformer

Contributors

  • Serge Rodovnichenko (SergeR) - FitTransformer
  • Ricky Dunlop (rickydunlop) - File::supportsExif()
  • Safonov Nikita (ns3777k) - removeLocal option

transit's People

Contributors

mfn avatar milesj avatar ns3777k avatar phindmarsh avatar redsoft7 avatar rickydunlop avatar schnauss avatar serger avatar sime avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

transit's Issues

s3 transporter auto-deleting

Hey! First off thank you for sharing transit :-)

As I can see, in Transit/Transporter/Aws/S3Transporter.php:166, file is always being deleted after successful upload to s3.
Maybe it'd be better to have this behavior as an option?

For example, I wanna upload the same file to s3 and rackspace (redundancy in case s3 is unavailable).
But I don't like the idea to extend this class over a simple option.

What do you think?

Certain remote URLs trigger \Transit\File::type() to return wrong $type

Sidenote: I'm using transit via deprecaed CakePHP Uploader Plugin on Linux.

Imagine an URL like: http://server/image.php?id=12312

\Transit\File::type() will perform the following steps:

  • $type is first determined via file -b --mime ... and gets detected as image
  • next, $ext = $file->ext() will return text/x-php
  • they do not match in this check later: $type !== $extType
  • $type will be forced to be the file extension type, basically ignoring the actual content type

This behaviour is problematic as serving an image via such an URLs is perfectly legit.

One approach could be to only use the extension if either the file -b --mime... and the finfo_file() logic do not work.

Problems with file_info mimetype check

I'm using the Uploader plugin to upload css and js files, but I've had to comment out the file_info() check for mime type in Transit/File.php because it returns the wrong type. It seems this is an issue with certain strings in the files that confuse the lookup database.

See: https://bugs.php.net/bug.php?id=53035

I'm seeing similar results to these folks - when uploading JS with opening comments it returns "text/x-c" as the type and my file goes from "script.js" to "script.c". I've set $ext = null in that method for now to get around the check so that it takes it from the extension.

I appreciate this being a security feature for user file uploads but my particular form is creating the file from a text input so I have control over the extension. It seems file_info() mime types are currently broken for text based files.

Issue within the rename function in the File class

I'm using your Uploader plugin with Transit in a CakePHP project. Great work.
The rename function in the File class doesn't check if the new file name already exists. This could causes an overwriting of files especially if the preg_replace method removes some unwanted characters. I think there should be also a check like in the move function.

bug with maintaining aspect ration while resizing the image

I used Uploader plugin with Transit plugin for Image staff in my project. I think I found little bug while resizing large images (large dimensions) to very small thumbnails. I was uploading image with dimensions 2000x2675px. My config was set to transform image to max 320x240px (width x height) and maintain aspect ratio when scaling down/up with width mode. But after the transformation, the image was re-sized to exactly 320x240px and the image was distorted.

Fix could be on the line 70 and 71 in the file "src/Transit/Transformer/Image/ResizeTransformer.php" with removing round() functions and leaving the code like this:
$widthScale = $width / $baseWidth;
$heightScale = $height / $baseHeight;

AWS Dependency

Hey

I'm using you library (which is awesome btw) but I'm having some dependency resolution problems with the aws version that Transit includes depends on an older version of the Guzzle client which results in conflicts that can't be resolved.

Is it possible to bump the aws/aws-sdk-php version to at least 2.1.0?

Thanks!

Transit rollback

Hi,
I'm facing some exceptions in rollback(), sometimes $file is not an object (happened when I used your Uploader plugin).

To solve it please changed:

        if ($files = $this->getAllFiles()) {
            foreach ($files as $file) {
                $file->delete();
            }
        }

Into:

        if ($files = $this->getAllFiles()) {
            foreach ($files as $file) {
                if($file) {
                    $file->delete();
                }
            }
        }

Validator failed to recognize file by mime

When I uploaded the .exe file that I renamed the extension to .pdf, validation failed to recognize the .exe file and thought the file was a .pdf file

'Uploader.FileValidation' => array(
'file' => array(
'extension' => array('pdf'),
'type' => 'application',
'mimeType' => array('application/pdf'),
'required' => true
)
),

my solution was added mime checking using finfo_open at AbstractValidator -> mimeType

public function mimeType($whitelist = array()) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $this->getFile());
return in_array($mime, (array) $whitelist);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.