I'm pretty new in Symfony, and I'm having a problem uploading a file
I just don't get it work, and I can't find something that tell me exactly how to use it or show me how it works (I had read smyfony official documentation)
this is my code:
the form
class PagosForm extends BasePagosForm
{
public function configure()
{
$this->setWidgets(array('file' => new sfWidgetFormInputFile()));
$this->widgetSchema->setNameFormat('pagos[%s]');
$this->setValidators(array('file' => new sfValidatorFile(array(
'required' => false
))));
}
}
the actions
public function executeSelect(sfWebRequest $request)
{
$this->form = new PagosForm();
}
public function executeUpload(sfWebRequest $request)
{
$this->form = new PagosForm();
if ($request->isMethod('post'))
{
$this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
if ($this->form->isValid())
{
echo "isvalid";
move_uploaded_file($_FILES["file"]["tmp_name"], sfConfig::get('sf_upload_dir').'/'.$_FILES["file"]["name"]);
}
else
{
echo "isinvalid";
//echo var_dump($this->form);
}
}
}
in select, there is outputed a button for selecting file and submit it: that takes us to the action Upload.
selectSuccess.php
<?php echo form_tag('pagos/upload', 'enctype="multipart/form-data"', 'method="POST"') ?>
<?php echo $form['file'] ?>
<?php echo submit_tag('Send') ?>
I have some problems with eclipse, so I'm using Sublime text 2 (a text's editor) for coding, so its difficult for me find the errors.
I use move_uploaded_file
because for some reason, I can't make it work the functions of symfony for uploading files. In this way, I can get it, but if I want to add some validation (for example, only allow to upload excel files), I can't get it work..
I always get line "isinvalid" printed, except I remove the line in the form that set validator. So, for some reason, the validator is not working..
I've tried to create my custom validator also, extending sfValidatorFile, but not working at all (I can't even upload any file or render the page)
So, I need a little help, before my head explodes (caused by symfony :P)
what is wrong with the code, that I always getting invalid file ? I'm trying to uploading a simple .txt of 3 KB, if I remove the valitadion, I can upload it normally