Get path of uploaded image in Moodle - moodle

I have added custom column to store company logo. I have used file api of moodle like :
$mform->addElement('filepicker', 'certificatelogo', 'Company Logo', null,
array('maxbytes' => $maxbytes, 'accepted_types' => '*'));
$mform->setDefault('certificatelogo', '0');
$mform->addHelpButton('certificatelogo', 'certificatelogo', 'certificate');
Once the form is submitted itemid will be stored in custom column. Say "648557354"
Now I need to get image to print logo on certificate. How can I get image path from itemid? Do I need to store any other information to retrieve image?

The itemid returned is the temporary id of the draft area where the file is stored whilst the form is being displayed. You need to copy the file into its 'real' location, when the form is submitted, otherwise the file will be automatically deleted after a few days (and it will only be accessible to the user who originally uploaded it).
I'd always recommend using the filemanager element, if you are planning on keeping the file around (filepicker elements are for files you want to process and discard, such as when uploading a CSV file data to parse and add to the database).
Details of how to use it are here:
https://docs.moodle.org/dev/Using_the_File_API_in_Moodle_forms#filemanager
But the basic steps are:
Copy any existing files from the 'real' area to the draft area (file_prepare_standard_filemanager).
Display the form.
On submission, copy files from the draft area to the 'real' area (file_postupdate_standard_filemanager).
When you want to display the file to the user, get a list of files stored in the file area (defined by the component, filearea, context and, optionally, itemid, you used in file_prepare_standard_filemanager and file_postupdate_standard_filemanager). You can do this with: $fs = get_file_storage(); $fs->get_area_files().
For those files (maybe only 1 file, in your case), generate the URL with moodle_url::make_pluginfile_url.
Make sure your plugin has a PLUGINNAME_pluginfile() function in lib.php, to examine incoming file requests, do security checks on them, then serve the file.
There is a reasonable example of all of this at: https://github.com/AndyNormore/filemanager

Related

Automatically download emails from Outlook with SAS or Outlook rule

I am trying to create a program to automatically download the attached files that are sent to us from a certain email and then transform the delimiter with SAS, of those csv that are attached to us and pass those csv through a flow that I have already created.
I have managed to create a program that treats the csv as I want and the delimiter that I want, the problem is that when it comes to automating the download of files from Outlook it does not work.
What I have done is create a rule with the following VB code that I found on the internet:
Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = "C:\Users\ES010246\Desktop"
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next
End Sub
I have changed the path to my personal path where i want the files are downloaded.
website: https://es.extendoffice.com/documents/outlook/3747-outlook
The problem is that this code does not work for me, it does absolutely nothing for me and no matter how much I search the internet, only this code appears.
Is there any other way to do with SAS what I want? What is it to automatically download 8 csv files sent to me by Outlook, or has someone experienced the same thing as me with VBA?
I have followed all the steps about 7 times so I think the error is not in copying the code or selecting certain options wrong, in fact I had copied and pasted the code and later I modified the path where I wanted those to be saved. files but it doesn't work, does anyone know why?
I will be tremendously grateful, thank you very much for everything!
First of all, you need to make sure the file name and path doesn't include forbidden symbols.
The VBA macro used for a rule in Outlook is absolutely valid except that a mail item may contain the attached files with the same name, so a file saved to the disk may be overwritten (saved with the same name). That's why I'd suggest generating a file name with your own unique IDs making sure that DisplayName property is not empty and has a valid name what can be used for file names (exclude forbidden symbols).
Also you may consider handling the NewMailEx event of the Application class which is fired when a new message arrives in the Inbox and before client rule processing occurs. Use the Entry ID returned in the EntryIDCollection string to call the NameSpace.GetItemFromID method and process the item. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem.
The Items.ItemAdd event can be helpful when items are moved to a folder (from Inbox). This event does not run when a large number of items are added to the folder at once.

DropzoneJS which one file is?

So, I use DropZoneJS for uploading images for individual products. But i make in database 6 columns for images
"image_1" "image_1thumb" "image_2" "image_2thumb" "image_3" "image_3thumb"
I make script for uploading images on the host and also to convert image to thumb...
So what i need. How i can detect first, second and third image?
I wanna first image name to write in "image_1" and in "image_1thumb", second in "image_2" and in "image_2thumb" and third one in "image_3" and in "image_3thumb"
The dropzone docs mentions a list of events... one being
complete
which returns the current file
So for the Dropzone post the processqueue event
this.on("complete", function (file) {
// this complete will be fired 3 times...in your case
});
you can manipulate the filename here or you can store then in order and later updated your database

Moodle File API : multiple rows?

In a Moodle form I perform a file upload using the filemanager element:
$mform->addElement('filemanager', 'attachment',get_string('displayedcontent', 'block_helloworld'), null, $filemanageropts);
Once the form is validated, when I record my instance in the database, I also save the uploaded file using the following function:
file_save_draft_area_files($form_submitted_data->attachment, $context->id, 'block_helloworld', 'attachment',
$form_submitted_data->attachment, array('subdirs' => 0, 'maxbytes' => 500000, 'maxfiles' => 1));
This is working fine but when I take a look at the DB table mdl_files, I saw that for my file there are 4 rows:
component fileare itemid filepath filename
block_helloworld attachment 706783489 / .
block_helloworld attachment 706783489 / test5.pdf
user draft 706783489 / .
user draft 706783489 / test5.pdf
There are 2 rows for my uploaded file in my component block_helloworld and in the component user.
One row has a filename but not the other one!
This sounds strange. Is that normal?
When I perform file deletion, how to delete all these files?
Note: I am using moodle v3.0.6
As far as I remember, this is normal behaviour. I had this issue, too, but when you cross check (like doing a file upload into a course) you will notice that there are 2 rows, too. Not sure, why but for me it was normal behaviour
The 4 entries are:
The folder that your file is in
The file itself
The folder that the draft version of the file is stored in whilst the form is being edited
The draft file whilst the form is being edited
The draft files will be automatically cleaned up after a day or so.

Umbraco 7. forms - path error when form transferred to document in Workflow (file upload)

I have a form with several fields that has a workflow to save as a document.
One of the fields is a File Upload.
This is matched to a document field of an Upload type.
All works well other than the File Upload in the resulting document has an error in the URL that is shown in the document:
It includes: ....umbraco/~/media/forms/upload....
Whereas it should be: ...media/forms/upload/...
The file uploaded is there, but the saved link is incorrect.
This does not seems to refer to the settings in FileSystemProviders.config or UmbracoForms.config
The later has a key for UploadStorageDirectory but has no effect.
Any suggestions would be great... John

Modus Operandi - Upload and Resize Multiple images using Zend Framework and HTML5

The good news:
I don't care if it uses ajax or not.
I don't care if the user must install a specific browser to make it work.
I don't care if there isn't any specifc progress bar.
The bad news:
I don't want to use flash.
The user must upload a file from any width or height - however no bigger then 8MB.
The file must be stored on a specific folder (or database column).
A thumbnail must be generated on a specific folder (or database column).
Those images must be associated with a specific record.
This is a "modus operandi" question, I realise that there is to much code involved here.
So:
We first create our form element to support multiple upload, like this:
$element = new Zend_Form_Element_File('multifile');
$element->setAttrib('multiple', true);
$element->setIsArray(true);
We then, need to add some validations and allowed extensions;
Then we need to process the upload;
Once the upload is done, we need to resize those multiple files according to our needs.
We need to store those resized files somewhere else.
Once all this is done, we are ready to display the files associated with a specific database record?
Is this the way to go? Should I have more steps? Am I missing something. I've never done this before, but I'm taking it like a challenge.
First, you create a form. Not much complication here:
$this->addElement('File','Filedata');
$this->Filedata
->setLabel('Select images')
->setDestination('somepath') //define & create it somewhere earlier ;)
->addValidator('Size', false, 1024000)
->addValidator('Extension', false, 'jpg,png,gif')
->setMultiFile(5)
->addValidator('Count', false, array('min'=>0,'max' => 5))
;
In the controller, you receive the images. They will have temporary random names, which you can keep later if you wish (I usually do).
$fileinfo = $form->Filedata->getFileInfo();
$path = 'somepath'; //make sure it exists
for($i=0;$i<5;$i++) {
if($fileinfo['Filedata_'.$i.'_']['tmp_name']) {
$img = new Imagick($fileinfo['Filedata_'.$i.'_']['tmp_name']);
// image processing goes here
file_put_contents('somepath',$img);
}
}
And that's it ;)