Thread overview | |||||
---|---|---|---|---|---|
|
December 20, 2016 Vibe.d form file attributes | ||||
---|---|---|---|---|
| ||||
In PHP, I am able to access the name attribute of multiple files submitted through forms at the server side in $_FILES global. For example, a file input with name="picture[]" will allow me to upload multiples files with the same attribute name. This can be access in PHP as; $files = $_FILES["picture"]; // This filter out only files with a name attribute of "picture[]" foreach ($files as $file) { $filename = $file["name"]; ... } Now I wanted to implement this in D (vibe.d) and here is what I did in the file upload handler. void upload(HTTPServerRequest req, HTTPServerResponse res) { import std.stdio; foreach(picture; req.files) // req.files includes all uploaded files { ... } } However, I want to filter out only those files with attribute name of "picture[]" from req.files. I tried req.files.name == "picture[]" and other combination but there seem to be no property like that (How do I print all properties of req.files by the way? :) ). Any help on this? |
December 20, 2016 Re: Vibe.d form file attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to aberba | On Tuesday, 20 December 2016 at 18:22:51 UTC, aberba wrote: > [...] > Now I wanted to implement this in D (vibe.d) and here is what I did in the file upload handler. > > void upload(HTTPServerRequest req, HTTPServerResponse res) > { > import std.stdio; > > foreach(picture; req.files) // req.files includes all uploaded files > { > ... > } > } > However, I want to filter out only those files with attribute name of "picture[]" from req.files. I tried req.files.name == "picture[]" and other combination but there seem to be no property like that iterate over req.files like this instead: foreach (name, picture; req.files) // name is "picture[]" now { ... } > (How do I print all properties of req.files by the way? :) ). pragma(msg, __traits(allMembers, typeof(picture))); |
December 20, 2016 Re: Vibe.d form file attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to WebFreak001 | On Tuesday, 20 December 2016 at 18:42:11 UTC, WebFreak001 wrote: > On Tuesday, 20 December 2016 at 18:22:51 UTC, aberba wrote: >> [...] > iterate over req.files like this instead: > > foreach (name, picture; req.files) // name is "picture[]" now > { > ... > } Nice. > >> [...] > pragma(msg, __traits(allMembers, typeof(picture))); Wow. I have a lot to learn :). PHP had spoon-fed me. |
Copyright © 1999-2021 by the D Language Foundation