brandonsavage / Upload

File uploads with validation and storage strategies
MIT License
1.67k stars 315 forks source link

more then 2 files #74

Open xensor opened 8 years ago

xensor commented 8 years ago

it seems to not like more then 2 files at a time.

how can we fix that?

brandonsavage commented 8 years ago

Could you use two objects?

On Wed, Nov 11, 2015 at 7:29 AM, Adelowo Lanre notifications@github.com wrote:

it does not have native support for that but you can always run a loop i guess

— Reply to this email directly or view it on GitHub https://github.com/brandonsavage/Upload/issues/74#issuecomment-155764685 .

yepwingtim commented 8 years ago

How can I do that? Im using name="foo[]". How can i access that array?

what i tried so far... new \Upload\File('foo[$i]', $storage);

Thanks

mrbarletta commented 8 years ago

For those struggling with this

1) get the latest version 2) This is my working code

I am using the react-dropzone to send "upload_files" array and this is how to use them

$storage = new \Upload\Storage\FileSystem(__DIR__."/".$sugar_config['upload_dir']);
    $file = new \Upload\File('upload_files', $storage);
    if (count($file)>1) {
        //Multiple file upload
        for ($i=0 ; $i <count($file) ; $i++) {
            // error_log(__FILE__." ". __LINE__." ". $i);
            // Access data about the file that has been uploaded
            $data = array(
                'name'       => $file[$i]->getNameWithExtension(),
                'extension'  => $file[$i]->getExtension(),
                'mime'       => $file[$i]->getMimetype(),
                'size'       => $file[$i]->getSize(),
                'md5'        => $file[$i]->getMd5(),
                'dimensions' => $file[$i]->getDimensions()
            );
$file[$i]->setName('newName');
}
// Single File upload, it doesn't support uploading each file reference
try {
            //Trying to save the File
            $file->upload();
        } catch (\Exception $e) {

            error_log(__FILE__." ". __LINE__." ". print_r($e, 1));

        }