digitalmars.D.learn - Vibe.d form file attributes
- aberba (28/28) Dec 20 2016 In PHP, I am able to access the name attribute of multiple files
- WebFreak001 (7/24) Dec 20 2016 iterate over req.files like this instead:
- aberba (3/12) Dec 20 2016 Wow. I have a lot to learn :). PHP had spoon-fed me.
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?
Dec 20 2016
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 thatiterate 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)));
Dec 20 2016
On Tuesday, 20 December 2016 at 18:42:11 UTC, WebFreak001 wrote:On Tuesday, 20 December 2016 at 18:22:51 UTC, aberba wrote:Nice.[...]iterate over req.files like this instead: foreach (name, picture; req.files) // name is "picture[]" now { ... }Wow. I have a lot to learn :). PHP had spoon-fed me.[...]pragma(msg, __traits(allMembers, typeof(picture)));
Dec 20 2016