File Upload In Zend - zend-framework

I have a Zend form with some elements like this :
http://i27.tinypic.com/ogj88i.jpg
I added all element using this way:
$element = $this->CreateElement('text','lockerComb');
$element->setLabel('Locker');
$element->setAttrib('class','colorbox');
$elements[] = $element;
$element = $this->CreateElement('text','parking');
$element->setLabel('Automobile / Parking');
$element->setAttrib('class','colorbox');
$elements[] = $element;
$element = $this->CreateElement('text','customes');
$element->setLabel('Customes Fields');
$element->setAttrib('class','colorbox');
$elements[] = $element;
But when i try to create element for file upload i fail..

Can you give more information about the exact nature of your fail?
It's fairly straight forwards to use. From the docs:
$element = new Zend_Form_Element_File('foo');
$element->setLabel('Upload an image:')
->setDestination('/var/www/upload');
Which is basic usage.
It's easy to get the file path wrong, but you should get an error if the path is wrong.
Supplying the code you are using would help!

I have written tutorial handling multiple file uploads with Zend Framework maybe it would help for you. Here is link to tutorial http://irmantasplius.blogspot.com/2009/08/zendform-multiple-file-uploads.html

Related

What is $index in facets count in algolia?

I have searched for $index in many sites but none of them define how to get value of this variable.For now i have to use Model for this like below:
Can someone please help me to solve this issue how to get $index in algolia facets count like below ?
$index->searchForFacetValues("age", ['filters' => 'age']);
I have already tried this many time but cant get the coreect result
$results = User::search($request->get('search'))->with(['filters' => 'age:23',]);
Want to get $index
I think you're looking for this snippet from the docs:
// composer autoload
require __DIR__ . '/vendor/autoload.php';
// if you are not using composer
// require_once 'path/to/algolia/folder/autoload.php';
$client = Algolia\AlgoliaSearch\SearchClient::create(
'YourApplicationID',
'YourAdminAPIKey'
);
$index = $client->initIndex('your_index_name');
You get $index by calling initIndex on your Algolia API client instance.
If that's not what you're looking for, you probably need to rephrase your question :)

Concrete5.7.5.2 - Where to put form file attachment headers?

I build my email headers like this:
$txt_message .= $this->txt_message;
$html_message .= $this->html_message;
$mh = Core::make('helper/mail');
$mh->to($this->email_to, $this->site_name);
$mh->from($this->email, $this->name);
$mh->replyto($this->email, $this->name);
$mh->setSubject($this->subject);
$mh->setBody($txt_message);
$mh->setBodyHtml($html_message);
#$mh->sendMail();
Some posts say an attachment can be added with
$mh->addAttachment($file);
but $file must be a file object. How can I make the uploaded file a file object?
I also found this post:http://www.adrikodde.nl/blog/2012/mail-attachments-concrete5/
But I get errors for all Zend stuff. Is Zend Mail still available in C5.7?
Where do I put headers for a file attachment? Where can I find out more about what really sends the message (is it still a Zend Mail?) and what methods are available?
Thank you.
[SOLVED]
Thanks to Nicolai, here's a working example for attaching files:
$file = $_FILES['image']['tmp_name'];
$filename = $_FILES['image']['name'];
$importer = new \Concrete\Core\File\Importer();
$file_version = $importer->import($file, $filename);
$attachment = $file_version->getFile();
$mh->addAttachment($attachment);
//Delete the file if not wanted on server
$attachment->delete();
PS. Don't forget to check the file really selected/exists/uploaded before you try to send it!
if (!empty($this->image)) {
$importer = new \Concrete\Core\File\Importer();
$image_version = $importer->import($this->image, $file_name);
if ($image_version instanceof \Concrete\Core\File\Version) {
$attachment = $image_version->getFile();
$mh->addAttachment($attachment);
}
}
#$mh->sendMail();
To add the file to your filesystem, you should take a look at this
http://concrete5.org/api/class-Concrete.Core.File.Importer.html.
On the returned object (which is a FileVersion on success), you should be able to call getFile( ) to get the actual Concrete5 File object

zfdatagrid - Plugin by name 'Table' was not found in the registry;

I've just installed the library and tried a simple table with an array
$grid = Bvb_Grid::factory("Bvb_Grid_Deploy_Table");
$grid->setSource(new Bvb_Grid_Source_Array($this->pkg));
$myGrid = $grid->deploy();
I get this error:
Plugin by name 'Table' was not found in the registry; used paths: Bvb_Grid_Template_: Bvb/Grid/Template/
I'm not familiar with how this works, but would guess looking at the error that it looks in the Bvb/Grid/Template/ directory, there is a Table.php in there with the class Bvb_Grid_Template_Table.Thank you.
Try a little bit different. Write "Table" instead of "Bvb_Grid_Deploy_Table". In my example there is also grid configuration file...
$config = new Zend_Config_Ini(dirname(__FILE__) . '/../configs/grid.ini','clients');
$grid = Bvb_Grid::factory('Table', $config);
$model = new Sand_Model_DbTable_Asset();
$source = new Bvb_Grid_Source_Zend_Table($model);
$grid->setSource($source);
/*
more code here...
*/
$myGrid = $grid->deploy();
$this->view->grid = $myGrid;

How Upload file using Mojolicious?

I have been trying out Mojolicious web framework based on perl. And I have try to develop a full application instead of the Lite. The problem I am facing is that I am trying to upload files to server, but the below code is not working.
Please guide me what is wrong with it. Also, if the file gets uploaded then is it in public folder of the application or some place else.
Thanks in advance.
sub posted {
my $self = shift;
my $logger = $self->app->log;
my $filetype = $self->req->param('filetype');
my $fileuploaded = $self->req->upload('upload');
$logger->debug("filetype: $filetype");
$logger->debug("upload: $fileuploaded");
return $self->render(message => 'File is not available.')
unless ($fileuploaded);
return $self->render(message => 'File is too big.', status => 200)
if $self->req->is_limit_exceeded;
# Render template "example/posted.html.ep" with message
$self->render(message => 'Stuff Uploaded in this website.');
}
(First, you need some HTML form with method="post" and enctype="multipart/form-data", and a input type="file" with name="upload". Just to be sure.)
If there were no errors, $fileuploaded would be a Mojo::Upload. Then you could check its size, its headers, you could slurp it or move it, with $fileuploaded->move_to('path/file.ext').
Taken from a strange example.
To process uploading files you should use $c->req->uploads
post '/' => sub {
my $c = shift;
my #files;
for my $file (#{$c->req->uploads('files')}) {
my $size = $file->size;
my $name = $file->filename;
push #files, "$name ($size)";
$file->move_to("C:\\Program Files\\Apache Software Foundation\\Apache24\\htdocs\\ProcessingFolder\\".$name);
}
$c->render(text => "#files");
} => 'save';
See full code here: https://stackoverflow.com/a/28605563/4632019
You can use Mojolicious::Plugin::RenderFile
Mojolicious::Plugin::RenderFile

Zend_Form_Element_File multiple file upload and mysql

Does anybody knows a working example to receive multiple files, store them in a folder and the names in a mysql table? Some days already with no luck at all, something always missing, and before putting those questions, well , maybe i can find the right one!
maybe?
i am learning using zend 1.11
thanks
pablo
EDIT:
i add the code for clearness:
in the form:
$element = new Zend_Form_Element_File('images');
$element->setLabel('Upload bis 3 Bilder (máx. 200kb each):')
->setMultiFile(3)
->setValueDisabled(true)
->addValidator(new Zend_Validate_File_Size('2MB'))
->addValidator('Count', false, array('min'=>0,'max' => 3));
in the controller:
$adapter = $form->images->getTransferAdapter();
//create directory where files would be hold
if (!file_exists(UPLOADDIR))
mkdir(UPLOADDIR, 0777, 1);
$i=0;
$images="";
//loop uploaded files
foreach ($adapter->getFileInfo() as $info)
{
//rename file how you like and move it to given destination
$fileName = time().$i.'.'.$this->getExtension($info['name']);
$adapter->addFilter('Rename', array('target'=>UPLOADDIR.$fileName, 'overwrite'=>true));
//if something goes wrong print errors in screen
if (!$adapter->receive($info['name']))
{
die(print_r($adapter->getMessages(),1));
}else{
if ($info['name']!==""){
$images .= $fileName.",";
}
}
$i++;
}
I think you should use setFilters() instead of addFilter on the adapter, because the current code will add a new Rename filter on each iteration of the foreach loop.
Try replacing:
$adapter->addFilter('Rename', array('target'=>UPLOADDIR.$fileName, 'overwrite'=>true));
with
$adapter->setFilters(array(new Zend_Filter_File_Rename(array('target'=>UPLOADDIR.$fileName, 'overwrite'=>true))));