It does before you call receive().
Afterwards the name of the file can not be the original name, because you
already said to use the new name.
Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com
----- Original Message -----
From: "Peter Smit" <[email protected]>
To: "Thomas Weidner" <[email protected]>
Cc: <[email protected]>
Sent: Friday, January 01, 2010 1:46 PM
Subject: Re: [fw-general] Random filename when using Zend_Form_Element_File
No it does not,
See here a print out (5 fileboxes, only first to are filled, with files
that
originally not where named php****)
Array
(
[file_0_] => Array
(
[name] => phpeH0S1G
[options] => Array
(
[ignoreNoFile] => 1
[useByteString] => 1
[magicFile] =>
)
[validated] => 1
[received] => 1
[filtered] => 1
[type] => application/octet-stream
[tmp_name] =>
/var/www/projects/mini-challenge/application/../data/uploads/phpeH0S1G
[error] => 0
[size] => 12650
[validators] => Array
(
[0] => Zend_Validate_File_Upload
[1] => Zend_Validate_File_Count
[2] => Zend_Validate_File_Size
)
[filters] => Array
(
)
[destination] =>
/var/www/projects/mini-challenge/application/../data/uploads
)
[file_1_] => Array
(
[name] => phptYoRli
[options] => Array
(
[ignoreNoFile] => 1
[useByteString] => 1
[magicFile] =>
)
[validated] => 1
[received] => 1
[filtered] => 1
[type] => text/x-log
[tmp_name] =>
/var/www/projects/mini-challenge/application/../data/uploads/phptYoRli
[error] => 0
[size] => 419
[validators] => Array
(
[0] => Zend_Validate_File_Upload
[1] => Zend_Validate_File_Count
[2] => Zend_Validate_File_Size
)
[filters] => Array
(
)
[destination] =>
/var/www/projects/mini-challenge/application/../data/uploads
)
[file_2_] => Array
(
[name] =>
[options] => Array
(
[ignoreNoFile] => 1
[useByteString] => 1
[magicFile] =>
)
[validated] => 1
[received] => 1
[filtered] => 1
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
[validators] => Array
(
[0] => Zend_Validate_File_Upload
[1] => Zend_Validate_File_Count
[2] => Zend_Validate_File_Size
)
[filters] => Array
(
)
[destination] => /tmp
)
[file_3_] => Array
(
[name] =>
[options] => Array
(
[ignoreNoFile] => 1
[useByteString] => 1
[magicFile] =>
)
[validated] => 1
[received] => 1
[filtered] => 1
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
[validators] => Array
(
[0] => Zend_Validate_File_Upload
[1] => Zend_Validate_File_Count
[2] => Zend_Validate_File_Size
)
[filters] => Array
(
)
[destination] => /tmp
)
[file_4_] => Array
(
[name] =>
[options] => Array
(
[ignoreNoFile] => 1
[useByteString] => 1
[magicFile] =>
)
[validated] => 1
[received] => 1
[filtered] => 1
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
[validators] => Array
(
[0] => Zend_Validate_File_Upload
[1] => Zend_Validate_File_Count
[2] => Zend_Validate_File_Size
)
[filters] => Array
(
)
[destination] => /tmp
)
[file_5_] => Array
(
[name] =>
[options] => Array
(
[ignoreNoFile] => 1
[useByteString] => 1
[magicFile] =>
)
[validated] => 1
[received] => 1
[filtered] => 1
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
[validators] => Array
(
[0] => Zend_Validate_File_Upload
[1] => Zend_Validate_File_Count
[2] => Zend_Validate_File_Size
)
[filters] => Array
(
)
[destination] => /tmp
)
)
---
+358 44 218 2700
On Fri, Jan 1, 2010 at 2:03 PM, Thomas Weidner
<[email protected]>wrote:
Use getFileInfo() to retrieve the original file infos your client sent.
This includes of course also the original filename.
Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com
----- Original Message ----- From: "Peter Smit" <[email protected]>
To: "Diego Potapczuk" <[email protected]>
Cc: "Thomas Weidner" <[email protected]>; <[email protected]>
Sent: Friday, January 01, 2010 12:51 PM
Subject: Re: [fw-general] Random filename when using
Zend_Form_Element_File
If I use this filter, I seem to be not able to retrieve the originial
filename anymore. Is this correct, or is there a way to do that?
My code:
class Form_Upload extends Zend_Form
{
public function init()
{
// Set the method for the display form to POST
$this->setMethod('post');
$this->setAttrib('accept-charset', 'UTF-8');
$this->setAttrib('enctype', 'multipart/form-data');
$this->addElement('file', 'file', array(
'label' => 'Files to upload:',
'multiFile' => 6,
'validators' => array(
array('Count', false, array('min' =>1, 'max' => 100)),
array('Size', false, array('max' => '500MB')),
),
'filters' => array(
'Rename' => array('target' => APPLICATION_PATH.
'/../data/uploads/'),
),
));
$this->addElement('submit', 'submit', array(
'ignore' => true,
'label' => 'Save',
));
}
}
public function indexAction()
{
if($this->getRequest()->isPost()) {
$form = new Form_Upload();
if (!$form->isValid($this->getRequest()->getPost()))
{
throw new Exception('Bad data:
'.print_r($form->getMessages(), true));
}
try {
$form->file->receive();
}
catch (Zend_File_Transfer_Exception $e)
{
throw new Exception('Bad data: '.$e->getMessage());
}
print_r($form->file->getUnfilteredValue());
print_r($form->file->getValue());
print_r($form->file->getFileInfo());
print_r($form->file->getFilename());
echo "File uploaded";
}
On Wed, Dec 30, 2009 at 4:15 PM, Diego Potapczuk <[email protected]
>wrote:
For some reason it has no link in the filter section, but you can find
informations about it in the Zend_File section.
http://zendframework.com/manual/en/zend.file.html
::: Diego Potapczuk
On Wed, Dec 30, 2009 at 11:07 AM, Peter Smit <[email protected]> wrote:
Somehow I can't find the documentation of this filter. Can somebody
give
me a hint where to find it?
Peter
On Wed, Dec 30, 2009 at 2:19 AM, Thomas Weidner <[email protected]
>wrote:
Attach the "Rename" file filter to the element.
Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com
----- Original Message ----- From: "Peter Smit" <[email protected]>
To: <[email protected]>
Sent: Wednesday, December 30, 2009 12:32 AM
Subject: [fw-general] Random filename when using
Zend_Form_Element_File
Hey,
When I am using this in my form
$this->addElement('file', 'file', array(
'label' => 'File to upload:',
'destination' => APPLICATION_PATH.'/../data/uploads',
'multiFile' => 3,
));
I have the problem that all files get their original name. This can
avoid
collisions as different people submit forms at the same time, or
even
upload
two file with the same name in the same form.
I would like to have a kind of randomized filename instead with a
method
to
retrieve the original filename. How can this be done, or how do
others
solve
it?
Regards,
Peter Smit
---
+358 44 218 2700