Using perl mime::entity for attaching files? - perl

below shows how one can add a file to a email being built using mime::entity
my question is instead of specifying a path to file, is there a way to add it via a varible which contains the context of the file, ??
### Attachment #2: a GIF file:
$top->attach(Path => "./docs/mime-sm.gif",
Type => "image/gif",
Encoding => "base64");

Yes, you can. You need to drop the Path parameter and instead use Data, e.g.
### Attachment #2: a GIF file:
$top->attach(Data => $my_gif_contents,
Type => "image/gif",
Encoding => "base64");
Data is a little bit buried in the MIME::Entity documentation, I must admit! I only know it from using the same parameter in MIME::Lite.

Related

Upload files to moodle under a selected course

I have created a particular course using the moodle rest api and i would like to add a files into that particular course. The course may take the week/topic form. I need to add the uploaded file under a selected topic/week how can i achieve that? .I used core_files_upload to upload files but how can i add it to a selected course?
Array
(
[contextid] => int
[component] => string
[filearea] => string
[itemid] => int
[filepath] => string
[filename] => string
[url] => string
)
In order to make a file appear in a course, you would need to create an instance of the 'mod_resource' activity in the course and then attach the relevant file to that resource.
I don't believe there is currently any webservice for creating activities within a course (https://tracker.moodle.org/browse/MDL-40779 appears to still be incomplete).
The best you can do at the moment would be to create a custom Moodle plugin (probably a local plugin) and then implement your own webservice in order to add this functionality.

How to create identifier_hash in typo3's sys_file?

I want to import some files in Typo3 system using external php Script. How do I create hash field value like identifier_hash folder_hash sha1 for sys_file table?
If I leave these fields empty there is error:
Attempt to modify record '3094' (sys_file_reference:3094) without permission. Or non-existing page.
Probably the best way to do this is to call TYPO3 API,
therefore you have to place somewhere in fileadmin/ and then call
TYPO3\CMS\Core\Resource\getFileObjectByStorageAndIdentifier($storageUid,
$fileIdentifier);
The hashIdentifier function in TYPO3 source utilizes the standard php-sha1 function, just in case you do not want to utilize the TYPO3-API.
$file = array(
'folder' => 'images',
'identifier' => 'images/foobar.jpg'
);
$identifierHash = sha1($file['identifier']);
$folderHash = sha1($file['folder']);
$sha1 = sha1_file($file['identifier']);

Zend Form file input set required false is not working

I'm having the following code to render a zend form file input
$pd_photo = new Zend_Form_Element_File('photo');
$pd_photo->setDestination(APPLICATION_PATH . '/../uploads');
$pd_photo->setRequired(false);
$pd_photo->setAllowEmpty(true);
$pd_photo->addValidator('Count', false, 1);
$pd_photo->addValidator('Size', false, 2097156672);
$pd_photo->addValidator('Extension', false, 'jpg,jpeg,png,gif,bmp');
$pd_photo->getValidator('Count')
->setMessage('You can upload only one file');
$pd_photo->getValidator('Size')
->setMessage('Your file size cannot upload file size limit of 1 MB');
$pd_photo->getValidator('Extension')
->setMessage('Invalid file extension, only valid image extensions are
(jpg, jpeg, png, gif, bmp) allowed.');
All is working fine but when I leave the file filed empty then, it does not work. The zend form validator returns an empty error string message.
What wrong am doing??
This is my first answer, this might be right because,
I also once had the similar problem, I saw that you have used both
$pd_photo->setRequired(false);
$pd_photo->setAllowEmpty(true);
In this case you should also define for 'NotEmpty' => 'false'
Try defining the above property for file element this should solve your problem, mine was resolved by this.

How to have jquery upload accept all file types but php & js

I have this line on Jquery file upload:
'accept_file_types' => '/.+$/i',
how to I modify that so it accepts all file types except PHP and Javascript files?
original
'accept_file_types' => '/.+$/i',
change with
'accept_file_types' => '/\.(gif|jpe?g|png)$/i'
or add new extension
'accept_file_types' => '/\.(gif|jpe?g|png|zip|pdf)$/i'

Is there a vim plugin that makes Moose attributes show up in Tag_List?

I am editing packages that use Moose, and I was wondering if there were a plugin for making Moose attributes show up in the Tag List.
For example, in the following code, the attribute options does not show up in Tag_List, but print_out_site does:
use Moose;
use MooseX::AttributeHelpers;
...
has 'options' => (
metaclass => 'Collection::Hash',
isa => 'HashRef[Str]',
is => 'ro',
provides => {
exists => 'exists',
get => 'get',
set => 'set',
},
);
...
sub print_out_site {
my $self = shift;
my $key = shift;
$self->fasta_out_fh->print(">", $key, "\n");
$self->fasta_out_fh->print($self->sites->{$key}, "\n");
}
Add the line
--regex-perl=/has '(.*)' => \(/\1/a,attribute,moose attributes/
to ~/.ctags and it should show up. You may need to tweak the regular expression to avoid spurious matches in other files or to accommodate different formatting for the attribute declarations in other files.
This extends ctags so that it detects another type of tag based on the regular expression when parsing perl files.
Then you need to tell the taglist plugin about the new tag type by adding this to your vimrc file:
let tlist_perl_settings='perl;c:constant;l:label;p:package;s:subroutine;a:attribute'
Geoff, I tried your code but it didn't work for me with the syntax you use. Could this be a version problem? I'm using exuberant ctags version 5.8.
I also modified the regex a bit because the quotes are optional and you might want to allow spaces (but nothing else) preceeding the 'has' keyword.
Here is what worked for me.
I created a $HOME/.ctags file (didn't have one yet, otherwise just add to it) with the following line:
--regex-perl=/^\s*has\s+['"]?([0-9a-zA-Z_]+)/\1/a,attribute/
Then added the line in .vimrc as you suggested
let tlist_perl_settings='perl;c:constant;l:label;p:package;s:subroutine;a:attribute'
Now it lists my attributes in Moose modules.
In addition, I find it useful to also have information about the parent class, roles and used modules show up in the taglist, so here is my complete $HOME/.ctags file:
--regex-perl=/^\s*has\s+['"]?([0-9a-zA-Z_]+)/\1/a,attribute/
--regex-perl=/^\s*with\s+(['"])(.+)\1/\2/r,role/
--regex-perl=/^\s*extends\s+(['"])(.+)\1/\2/e,extends/
--regex-perl=/^\s*use\s+([^ ;]+)/\1/u,use/
and this is what I have in .vimrc (you can change the order of tags in the taglist simply by changing the order in the tlist_par_settings):
let tlist_perl_settings='perl;u:use;p:package;r:role;e:extends;c:constant;a:attribute;s:subroutine;l:label'
let Tlist_Show_One_File = 1
Because of the additional content I find it useful to use the Tlist_Show_One_File option, which forces the taglist to show only the tags of the currently selected file.
To temporarily hide some of the tags you can always move the cursor to the tag name and hit "zc" (and "zo" to reopen) the fold.