D in accounting program
Adam D. Ruppe
destructionator at gmail.com
Thu Nov 25 10:09:09 PST 2010
Mengu asked:
> how did you handle file uploads and user sessions?
File uploads are passed through CGI applications through
stdin. My Cgi class (http://arsdnet.net/dcode/cgi.d) supports
it through an associative array interface:
====
struct UploadedFile {
string name;
string filename;
string contentType;
immutable(ubyte)[] content;
}
immutable(UploadedFile)[string] files;
=====
So if you have a file upload form, the file sits there in memory.
The maximum size of file is set in the constructor (defaults
to ~5 MB to avoid using too much memory).
A better way might be to replace the AA with a range that
lazily reads stdin, but I wanted to keep it simple.
To save it in code, you just:
std.file.write("myfile.png", cgi.files["name-from-form"].content);
User sessions are just done through the mysql database, with
a key that comes from a cookie and the user agent and ip address.
I didn't bother with anything like PHP's $_SESSION - the
active_sessions database table works better anyway.
More information about the Digitalmars-d
mailing list