Open Blackskyliner opened 12 years ago
I would like to have multiple file upload as well.
@Blackskyliner Did you solve this?
@ruian Do you have any plans adding this. I would be ready to contribute, just want to discus implementation with you first.
Yea... No I did just not used this package and build some not-so-fancy manual form upload through browser form elements...
@Blackskyliner Can I see your solution?
Entitiy:
<?php
/**
* @var string
* @ORM\Column(type="array", nullable=true)
*/
protected $bilder;
/**
* @var array
*/
protected $bilder_upload;
Type (with entity as prop class):
<?php
$builder->add(
'bilder_upload', 'file', array(
'label' => 'Bilder',
'required' => false,
'attr' => array(
'accept' => 'image/*',
'multiple' => 'multiple'
)
)
);
Controller (mergin new and old images and set them in the ORM handles prop, also reset the upload one):
<?php
/** @var $fum \SomeBundlePath\Service\FileUploadManager */
$fum = $this->get('somebundlepath.service.fileuploadmanager');
$realImages = array();
foreach($entity->getBilder() as $bild)
{
$realImages[] = $bild;
}
$uploads = $fum->uploadFiles($entity->getBilderUpload());
foreach($uploads as $bild)
{
$realImages[] = $bild;
}
$realImages = array_unique($realImages);
$entity->setBilder($realImages);
$entity->setBilderUpload(array());
//doing some flushing down here...
UploadService function (the commented stmts. could be used in some cases to check or whatever, but I just want to put it in ;) ):
<?php
public function uploadFiles(array $files)
{
//if($files == null) return array();
$retVal = array();
foreach($files as $file){
if($file != null && $file->isValid())
{
$fileHash = sha1_file($file->getRealPath());
try{
$fileName = $fileHash.'.'.$file->guessExtension();
$file->move($this->upload_dir, $fileName);
$retVal[] = $fileName;
}catch(\Exception $e)
{
//$retVal[] = false;
}
}else{
//$retVal[] = false;
}
}
return $retVal;
}
@Blackskyliner Thanks, I'll try if I fail with Uploadify :)
Ahh something I need to tell you though - what I forgot to write in the part above - is that after you created the formView you need to do this in the Controller before submitting it to the template:
<?php
$formview = $form->createView();
$formview->getChild('bilder_upload')->set('full_name', $formview->getChild('bilder_upload')->get('full_name').'[]');
I know its a bit hacky, but it seems to be the only way to mark its name as array, so you can multi-upload in modern browsers. It will be just a single filed though, but you can select multiple files in the dialog that appears for selecting the files, but thats kinda browser specific. e.g. the IE does not support multiple-choice upload. But in Chrome and FF it works like a charm. The merging mechanism can be used for sequential uploading though... I use this for my edit of the entity for those who just use an IE so they can upload more than one image in each step of profile editing, etc.
With some JS magic you could expand this method even more and add the uploadfile fields dynamically. Whereas the name would be the same for all fields I think... would need to have to do some testing there... But as my site needs to be fully functional without JS I didn't done it till now... maybe when the corefeatures are done I will beatufy sme controls here and there with JS, like the multiupload, etc.
I will write an example using uploadify for multi upload soon
@ruian Please define soon. :) Is it possible at all, you need to add new option, which is not used in bundle.
I already use it for multi upload in a backend apps, it's just i need some time to make it cleaner
Can community help? :)
sure :) you are welcome
@ruian We need your source to make it cleaned together.
the fact is i used it for multi upload with a previous version. So i think that a better way is to let start add new stuff to this bundle to allow user to switch between Single or Multi upload style. With FormType options, and it will choose the right script into the twig template associated to the type
@ruian Why not open full Uploadify interface by letting customer to pass array of options which will be directly converted to json and passed to Uploadify?
can you give me an example of what you mean ?
hmm yeah it could be nice. I think a good way to make this bundle better is to add an extension, with all this allowed options from uploadify lib
It's important to be configurable per form, not from global config, since you want to use different option sets on different pages/forms.
the extension extend 'file' so it let you add every options (declared in the extension) you want to your type, and a listener who transformed the specific type to a hidden field and add a uploadifyType
Can you start implementing it, and I'll see how I can help, just give the initial idea. Maybe we can open separated branch for this?
yep i will create a dev branch
Tonight i will push some features into the dev branch, because during journey i have no time ;)
Great, thanks!
So i start a dev branch, but it still a garbage one. I will continue to work on it as soon as possible.
Great, thanks.
@umpirsky i have made an update on the dev branch you should have a look and give me your feedback :), there is some work to do but it's already works
Seems promising... Will test it as soon as possible :)
It needs to be patched for master though... As there is the FormType::buildForm() changed in the Way that you'll need to have a FormBuilderInterface as the first param.
Hi there,
I wanted to use this bundle for my file upload but I don't know who I need to do the entity-wiring and form building to actually have this stored as a e.g. doctrine-array type or n-1 mapping... Could you provide a simple Example for this case?
Thanks in advance, Blackskyliner