I have an issue like this with TYPO3.
I have an object, this object has file attribute, this field named "pdf"
In the TCA this field I defined like this:
'pdf' => array(
'exclude' => 1,
'label' => 'LLL:EXT:locations/Resources/Private/Language/locallang_db.xlf:tx_locations_domain_model_location.pdf',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'files', array(
'appearance' => array(
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference',
),
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
)
),
And now I can upload a file or image for this field, but there are some things does not good:
I want to allow PDF files only
After upload one file, if I upload another file, is said that "The existing files be overwritten" but old file never be overwritten.
The new one is also not uploaded.
What I need for this case: If I upload a new file, the old file will be overwritten by the new one.
Thanks for your help.
Since you pass in $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] you are currently allowing all kind of image-like file extensions. This is the point where you might want to use 'pdf' instead.
If you want to overwrite files, you'll need to to this in the File module of TYPO3. If you want to put a different file in your relation, you can remove the current one and add another one. The first file won't be deleted automatically but your record will have a relation to the new file.
Related
Hi I uploaded files and stored in app/views/xxx/yyy.
Now i would like to download the files
If the file is PDF it is opened in new Tab and rest of them are downloaded, I need all files to be opened in new tab.
Here is my Code :
$this->view = 'Media';
$params = array(
'id' => $fileName,
'name' => $fileNameWOExtn,
'download' => false,
'extension' => $fileExtn, // must be lower case
'path' => APP . 'views' . DS .'static' . DS. $url .DS // don't forget terminal 'DS'
);
LogUtil::$logger->debug('Media View Params : '. var_export($params, true));
$this->set($params);
Not every file can be opened in the browser. A lot of file type encodings are proprietary and require their specific program to read and interpret them. PDFs, plain text files, some images, etc (with some exceptions) are the only types that browsers can recognize.
What types are files are you trying to render?
I am using the 'MeioUpload' plugin found here 'https://github.com/jrbasso/MeioUpload' and Cakephp 2.x.
Currently using this for single image uploads, please can anyone give advice on how to handle multiple image uploads using this plugin. Currently the db table storing the images holds filename, dir, mimetype and filesize fields for each image. I want to store more than one image for each of my posts when adding a new post. Any help would be much appreciated, thanks in advance :).
As I mentioned in my comment, you might want to try https://github.com/josegonzalez/upload as MeioUpload is now deprecated, and it's developer is working on that new upload plugin I linked to.
Either way, the following info for MeioUpload holds true for the new plugin, too.
MeioUpload is built to handle one uploaded file per corresponding set of fields. I don't think the example in MeioUpload's ReadMe is ideal, as it seems to imply that you have to have a table of 'images', where as in reality, you can have a table of just about anything, where each record holds one or more uploaded files (be it images, PDF's, MP3's... anything).
So, with that in mind, you have two solutions:
1) If your posts will have a potentially infinite number of images (ie, not a fixed, small number) then you can have Posts and Images in separate tables, and set up a hasMany relationship between them. See http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html
2) If you know that each post will only have a max of say 3 or 4 (or some other relatively small number) of images, then you can implement 3 (or 4, or X) sets of image fields in your Posts table / model, each to handle a separate upload. They'd be named, eg. featured_image_filename, feautred_image_dir, etc; image2_filename, image2_dir, image2_mimetype, etc; image3_filename, image3_dir, etc.
Your acts as would look something like:
var $actsAs = array(
'MeioUpload.MeioUpload' => array(
'featured_image_filename' => array(
'fields' => array(
'dir' => 'featured_image_dir',
'filesize' => 'featured_image_filesize',
'mimetype' => 'featured_image_mimetype'
),
),
'image2_filename' => array(
'fields' => array(
'dir' => 'image2_dir',
'filesize' => 'image2_filesize',
'mimetype' => 'image2_mimetype'
),
),
'image3_filename' => array(
'fields' => array(
'dir' => 'image3_dir',
'filesize' => 'image3_filesize',
'mimetype' => 'image3_mimetype'
),
),
)
);
This second solution is hardly ideal database design, but sometimes when you know there'll never be more than a few images, it's just the easiest way to do it - both in terms of developing, and in terms of an easy to use UI.
Make sense?
In my cakephp web page, I have a button that the user clicks and it performs some maintenance on the server and then presents a download to the user. The file download is testlogs.gzip but when the download option occurs in firefox, it comes up as a file type of html document.
The file downloads and extracts fine, but I want the file type to be correct.
Here is the Media view class for the download:
//$this->autoRender = false;
$this->viewClass = 'Media';
$params = array(
'id' => 'systemlogs',
'name' => 'testsystemlogs',
'download' => true,
'extension' => 'gzip',
// 'mimeType' => 'zip',
'path' => DS . 'home' . DS
);
$this->set($params);
I tried to add in the 'mimeType' => 'zip' but that did not work.
Any help would be great.
Thanks
UPDATE: I tested uploading of the same files and I used firebug to determine the content type. The only file types I care about are of type: application/octet-stream.
So I think I just need to set this type in the Media class settings, not sure how to do that though.
THanks
mimeType has to be specified as an associative array (extension -> type), in your case this would be array('gzip' => 'application/x-gzip'). CakePHP merges this array with the built-in array of known MIME types in CakeResponse class.
However, CakePHP already knows the MIME type of .gz files so changing the extension of your file, if it is an option, might be an even easier solution.
I am trying to get the file that the user has selected from the media selector from the media module in Drupal 7.
My form contains the selector and can upload and select a file successfully, but unable to get the name of the file that has been chosen.
My form for the selector:
$form['file'] = array(
'#type' => 'media',
'#title' => t('Screenshot'),
'#description' => t('Upload an image of the feature (Optional)'),
),
);
I need to get the details of the selected file (e.g. name, directory)
Try to use hook_submit to check the file name.
Suposing the file field in your form is named "file":
function your_form_submit($form, &$form_state) {
$file=$form_state['values']['file'];
// do something...
file_save($file);
You can use form_vaidate as well, i don't know exactly what you want to do with the file name...
I'm working on a website that has a file management portion where users can create folders and upload files. The folders CAN have subfolders. The folders are not actually created on the file system; they are just in the database. The files are created on the file system and information about the files are in the database.
I'm trying to make it so that if a user deletes a folder, it marks that folder as well as its subfolders and files as deleted. So let's say a user deleted a folder called "Main" that had this structure:
Main
Main\Subfolder\file.txt
Main\Subfolder 2 <-- empty folder
Main\Subfolder 3\image.jpg
I am able to mark all of the folders' deleted field with a "Y" like this:
foreach ($folders_to_delete as $folder_to_delete) {
$updateAll_conditions['OR'][] = array('id' => $folder_to_delete);
}
$this->UserFolder->updateAll(array('UserFolder.deleted' => "'Y'"), $updateAll_conditions)
But I want to mark all of the folders' deleted field with a "Y" AND all of the files that belong to those folders... with one query. Is that possible?
This problem becomes even more complicated when you consider that a folder might contain another folder!
You ultimately will want a script that can handle file structures of arbitrary complexity.
I suggest running a recursive function over the file structure in question and add the records that need updating to a massive $this->data array.
Then, do a saveAll (or updateAll) on that array.
Here's what a $this-data array might look like for a saveAll with multiple models affected:
$this->data = array(
'Folder' => array(
0 => array('deleted' => 'Y'),
1 => array('deleted' => 'Y'),
),
'File' => array(
0 => array('deleted' => 'Y'),
1 => array('deleted' => 'Y'),
),
)
I'll keep this answer to the model related stuff, if you want help w/ the recursive function, let's do that that in a separate question.