python - Saving temporary files with CGI (Ubuntu) -
i postdoc , finished cool little scientific application in python , want share world. it's useful tool genetecists.
i'd let people run program through cgi form interface. since i'm not student anymore, no longer have webspace tidy little cgi-bin
subdirectory that's hooked perfectly.
i wrote simple cgi python program few years ago, , trying use template.
here quesion: program needs create temporary files (when run command line saves images given path). i've read couple tutorials on apache, etc. , got lots of things running, can't figure out how let program write temporary files (i don't know these files live, etc.). time try write file (in manner) in python program, cgi "crashes" , doesn't seem ok.
i not extremely worried security because temporary files outputs of program (not user input).
and while i'm asking (i'm assuming you're kind of cgi ninja if got far , weren't bored), know cgi program can take file argument without making temporary file?
my previous approach take list of text argument:
try: if item.file: data = item.file.read() if check: tools_file.main(["exename", "-d", "-w " + data]) else: tools_file.main(["exename", "-s", "-d", "-w " + data]) ...
i'd the right way! cheers in advance.
stack overflowingly yours,
oliver
well, "right" way re-work things using existing web framework django. it's overkill in case. don't underestimate security aspects here. they're more relevant think.
all said, want use python's temp file module standard library:
http://docs.python.org/library/tempfile.html
it'll write stuff out /tmp/whatever if you're on unix. if program crashing when run under apache (but runs fine when execute directly), check permissions. make sure apache user has permission write wherever you've decided store temp files. make sure temp files written appropriate permissions (don't want write file can't read later on).
Comments
Post a Comment