Input files from ExpressionEngine? - input

Is there a way to reference uploaded files using EE's Input class? I know it has a "post" method to get post variables, but what about files?

Not in the input class, you can just use $_FILES.
You may want to have a look at the Upload class though. For a good overview of how it works, you can check out the function _upload_file() in the Filemanager library file within your EE directory. A primer:
$this->EE->load->library('upload');
$this->EE->upload->initialize($config);
if ( ! $this->EE->upload->do_upload($field_name))
{
return $this->_upload_error(
$this->EE->upload->display_errors()
);
}
$file = $this->EE->upload->data();
The $config array contains the options for the upload, which you can review in the CodeIgniter docs.

Related

how to read a test data file ( a json file) in a feature file only once

Karate has callonce that will call a function or feature only once for all scenerios in a feaure file? Is there a similar feature for reading a json file only once in a feature file before executing all scenarios. Can this be achieved by passing a function to karate.callonce() and that function will then just use read function to read the json file. Kindly answer how can I do this correctly?
I do not want to use another feature file for this. Should be able to pass a function name to the callonce.
I tried karate.callSingle and pass read function to read the json file.
Personally I think reading a JSON file from the file-system is so cheap that you are un-necessary worrying about this.
The only way that I know of is like this:
Feature:
Background:
* def dataFn = function(){ return read('data.json') }
* def data = callonce dataFn
Scenario: one
* print data
Scenario: two
* print data
But you are quite likely to complain here that we are initializing the function dataFn for every Scenario ;) In that case, you may need to look for another framework.
And I personally think calling a re-usable feature (for data set-up) is fine. Programming languages do this kind of re-use all the time.
EDIT: well, I just remembered that this would work:
* def data = callonce read 'data.json'
Explained here: https://github.com/karatelabs/karate#call-vs-read

Iterating through a directory of xml files in zorba

I have a directory called auction containing a list of xml files.
How can I create a script to iterate through each file and perform operations. I am trying to use collection(), but it is not working.
for $relpath in collection("auction")
for $b in $relpath/people/person[#id = "person0"] return $b/name/text()
Please help.
More info will be provided if required
The answer was found here:
https://groups.google.com/forum/#!topic/zorba-users/8W2xOQ2j0Vw
Modified it to suit my purposes. An example is as follows:
import module namespace file="http://expath.org/ns/file";
for $relpath in file:list("auction", fn:true(), "*.xml")
let $abspath := fn:concat("auction/", $relpath)
for $b in doc($abspath)/people/person[#id = "person0"] return $b/name/text()
Firstly, the module needs to imported to be used which contains the list function, which shows all the contents.
Then the iterations can go through each file and open it as a document. However, the name of the folder needs to concatenated with the filename

Read Velocity Tokens/Tag from .vm file

I have an application where in I am trying to create a velocity template repository which will help me centralise all my email templates and will allow me to create a communication hub. All templates will be called at runtime and populates with data via services.
My problem is that I need to provide users with optional and compulsory params list when they define the template inputs for the velocity template.
Is there a way to read the tokens/tags from the velocity template file and extract them??
Like I want a list of tokens $name.address.streetName to be available to me from .vm file.
I do not want to go for Regex .
I do not have to cache or reuse them , its just going to be a one time read and store the default,compulsory & optional params in the database.
I am following these patterns : http://kickjava.com/src/org/apache/velocity/test/view/TemplateNodeView.java.htm
How to use String as Velocity Template?
Please advice.
I got it working like this
RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();
StringReader reader = new StringReader(String velocityTemplateBodu);
SimpleNode node = runtimeServices.parse(reader, "dummyOne.vm");
for(int i=0; i<node.jjtGetNumChildren();i++){
if(node.jjtGetChild(i) instanceof org.apache.velocity.runtime.parser.node.ASTReference ){
System.out.println("Node -----------------"+i +"---"+node.jjtGetChild(i).literal());
}
}
Using SimpleNode class you get all the nodes on the .vm file.
The Nodes are read using javaCC as ASTReference and ASTText (both extend SimpleNode). To get the tokens you need to get the ASTReference and to get HTML text use the ASTText.

Generating PDF Symfony2 IoTcpdfBundle

I'm generating pdf file with IoTcpdfBundle using Symfony2, but there's a strange behaviour that I don't understand.
When I'm on the controller, I generate the pdf file like this:
$html = $this->renderView('MyBundle:Docs:solicituddevacaciones.pdf.twig', array());
return $this->get('io_tcpdf')->quick_pdf($html);
Those lines generate the pdf file. Everything's fine, I can right click on the file to save it and it's a .pdf file.
But when I receive some data using a form, and I put the lines inside the:
if ($request->getMethod() == 'POST') {
$year = $this->get('request')->request->get('year');
$date= $this->get('request')->request->get('date');
$html = $this->renderView('SoflaSoflaBundle:Documentales:solicituddevacaciones.pdf.twig', array());
return $this->get('io_tcpdf')->quick_pdf($html);
}
When I right click on the file to save it, it's not a .pdf file, the browser suggests that I should save the file as a .htm
Why is this happening? I need users to be able to save the files as .pdf files.
Need help with this please.
I had some similar problems and found out that the bundle might be outdated by now. I had to change some of the settings, most importantly adding another header to quick_pdf function of Tcpdf class in 'Helper' folder of the bundle:
$response->headers->set('Content-Disposition', 'attachment; filename="'.$file.'"');
Now it's working like a charm, calling it in the controller like:
$html = $this->renderView('Bundle:Item:print.pdf.twig', array(
'some' => $this->value,
));
return $this->get('io_tcpdf')->quick_pdf($html, "yourFileName.pdf");
Try to save the html (or better yet, left click instead of right click) and check the contents of that file. You probably have an error in ther somewhere, and that html file is the one generated by symfony to explain the error.

HTML File API: getting the text 'onprogress'

Using the HTML5 File API, I wonder if I can process the content of a file on the fly.
I know I can get the content of the file when onload is called:
function fileLoaded(e)
{
alert("content is "+e.target.result);
}
but can I get the current content when onprogress is called ?
Thanks.
Seems like yes, according to the spec. The onprogress event will fill the result property of your FileReader as more data is read in. However, as Matt pointed out, if you're only interested in a portion of the file in the first place, only read that section:
var blob = file.webkitSlice|mozSlice(startByte, stopByte, contentType);
reader.readAsBinaryString(blob);
I don't think so, but look at this example which shows you how to read slices of files.