how to get files inside the folder to be zip Archive - zend-framework

$source="/Filelist/"
$filter = new Zend_Filter_Compress(
array(
'adapter' => 'Zip',
'options' => array(
'archive' => test.zip
)
)
);
$result = $filter->filter($source);
the function work fine ,the problem is that i want to get the file list inside the test.zip .but now i am getting the folder Filelist inside the archive.
it seems to because of line $content = str_replace(array('/', '\'), DIRECTORY_SEPARATOR, realpath($content)); and the realpath is removing '/'
Any solution ????????????????

Looking at the code, I don't see a way of doing that. Zend_Filter_Compress_Zip checks if it is a dir, and if it is, calls:
$zip->addEmptyDir(substr($local, 0, -1));

Related

Set different directories to upload files in TYPO3 from a single field

I have a field in TCA with type group->file and I need to save the files in different directories depending on the year.
Usually when I need to pos-process any field I use the processDatamap_afterDatabaseOperations hook but it is not working properly with files.
This is what I'm doing.
function processDatamap_afterDatabaseOperations ($status, $table, $id, &$fieldArray, &$reference) {
if ($table=='tx_students' && isset($fieldArray['documents'])){
$path = $_SERVER['DOCUMENT_ROOT'].'/folder/';
$folder = date('Y').'/';
$filename = date('Y-m-d').' '.$student['first_name'].' '.$student['last_name'].'.zip';
$filename = str_replace(' ','_',$filename);
if (!file_exists($path.$folder)) {
mkdir($path.$folder, 0755, true);
$fh = fopen($path.$folder.'index.html','w+');
fclose($fh);
}
rename($path.$fieldArray['documents'],$path.$folder.$filename);
$GLOBALS['TYPO3_DB']->exec_UPDATEquery($table,'uid='.$student['uid'],array('documents'=>$folder.$filename));
}
}
I'm trying to store the filename in the DB with the folder path and that works well the first time I save the form. But the following times I get an error because TYPO3 can't find the file. It happens when I try to delete the file as well clicking in the x.
This is the TCA for that field:
'documents' => array(
'exclude' => 1,
'label' => '',
'config' => array(
'type' => 'group',
'internal_type' => 'file',
'allowed' => 'zip',
'max_size' => $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'],
'uploadfolder' => 'uploads/incoming',
'show_thumbs' => 1,
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
),
),
I want to have those files organized by year but I don't know how to do this in TYPO3. Is it another hook for doing this? It seems like TYPO3 was removing the part of the path before the slash for certain operations.
I'm working with TYPO3 4.5 LTS. Any suggestions?
upgrade to 6.2 beta
use fal
use the categories to sort / categorize your files.
The directories you are using are not intended to be used this way ;)

Zend Framework Cache creates new file and doesnt load it

i'm having a little problem with Zend Framework Full Page Cache.
My current Bootstrap configuration looks like this:
$dir = PUBLIC_PATH . "/tmp/";
$frontendOptions = array(
'lifetime' => 6000000000,
'content_type_memorization' => true,
'default_options' => array(
'cache_with_get_variables' => true,
'cache_with_post_variables' => true,
'cache_with_session_variables' => true,
'cache_with_cookie_variables' => true,
),
'regexps' => array(
'^/.*' => array('cache' => true),
)
);
$backendOptions = array(
'cache_dir' => $dir
);
// getting a Zend_Cache_Frontend_Page object
$cache = Zend_Cache::factory('Page',
'File',
$frontendOptions,
$backendOptions);
$cache->start();
which worked perfectly before changing our development system to the live one.
Now if we enable the caching system it creates the correct cached file in the correct path but doens't load it.
So for every request another cache file is created but the old one NEVER gets loaded.
Maybe anyone has had this problems before and can give me a hint?
Thanks in advance!
there might be issue with permission to move from development environment to live.
The tmp directory is writable by myself and other users of the same group and also apparently Zend will access the files as another user. The solution was to chmod 777 on the folder, making it writable.
let me know if i can help you more.

How to move an image from temp folder to a folder inside the project in server in zend framework?

I have form where user can upload an image. I am working locally and when a user uploads a photo it added in the temp folder then I need to move it to folder inside the project. I need to know how to do this in live server.
Thanks
If you want to do it with Zend Framework, use Zend_Filter_File_Rename:
$moveTo = '/uploads';
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('Count', false, array('min' => 1, 'max' => 1))
->addValidator('Size', false, array('max' => '2000kB'))
->setDestination($moveTo);
if (!$upload->isValid()) {
return false;
}
$upload->receive();
$name = $upload->getFileName();
$newFile = "nefile.png";
$filterFileRename = new Zend_Filter_File_Rename(array(
'target' => $moveTo . '/' . $nefile;
'overwrite' => true
));
$file = $filterFileRename->filter($name);

Overwrite uploaded file in Zend Framework

How do I upload a file, move it to a directory and keep the filename while overwriting any existing file? In Zend Framework.
This maintains the tmp filename (like php3382.tmp)
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination('data/');
$adapter->addFilter('Rename', array(
'target' => 'data/',
'overwrite' => true
));
$adapter->receive();
and this doesn't overwrite
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination('data/');
$adapter->receive();
Try this:
...
$adapter->addFilter('Rename', array('overwrite'=> true,
'target'=> sprintf('data/%s',
$adapter->getFileName()),
));
$adapter->receive();
....

Upload and encrypt a file using Zend_File_Transfer_Adapter_Http

In Zend Framework documentation titled "Filters for Zend_File_Transfer", it said file can be encrypted and saved as a different name using the filename option.
This filter supports one additional option which can be used to save the encrypted file with another filename. Set the filename option to change the filename where the encrypted file will be stored. If you suppress this option, the encrypted file will overwrite the original file.
How do I specify the filename option? I tried:
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addFilter('Encrypt', array('adapter' => 'mcrypt', 'key' => 'mykey'), 'file.txt');
and
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addFilter('Encrypt', array('adapter' => 'mcrypt', 'key' => 'mykey', 'filename' => 'file.txt'));
both don't seem to work.
I took a look into Zend/File/Transfer/Adapter/Http.php and it does not seem that filename is a valid option for this adapter.
Maybe this is a Bug in the Documentation.
Instead you could use the Rename-Filter to change the filename.
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addFilter('Rename', array('target' => APPLICATION_PATH . '/../data/file.txt'));
$upload->addFilter('Decrypt', array('adapter' => 'mcrypt', 'key' => 'mykey'));
$upload->receive();