[Image-SIG] Deliver me from Kludgehood - PIL, filesystems and state
Doug.Shawhan@gecits.ge.com
Doug.Shawhan@gecits.ge.com
Fri, 6 Dec 2002 13:54:09 -0500
I have written the following abomination under windows2k:
I have written an embarassingly simple cgi script that cleans up old image
directories, grabs an image, performs (no) manipulation (as of yet),
creates a new directory for the image, writes the image and displays it. The
problems with this are many - if more than one person attempts to view the
page at once, then the earlier viewer will have a good chance of having his
pic wiped out before it can be displayed.
My question: is there a method to place an image in a page *without* writing
it to the filesystem, thus avoiding keeping state and the security risk of
allowing write access?
Thanks all!
d
---------------------------------yuk----------------------------------------
--
#!c:/python22/python.exe -u
import cgi
import cgitb; cgitb.enable()
import os, string, random, time, glob
import Image
print 'Content-type: text/html\n\n'
print 'yo'
old_dirs=glob.glob("\\Program Files\\Apache Group\\Apache2\\htdocs\\img\\*")
for each in old_dirs:
if os.path.isdir(each):
os.remove("%s\\hai.jpg"%each)
os.rmdir(each)
dirnm=str(random.randint(100,1000))
newImageDir="\\Program Files\\Apache
Group\\Apache2\\htdocs\\img\\%s\\"%dirnm
os.mkdir(newImageDir)
gak=Image.open("pics\\karate.jpg")
gak.save("%shai.jpg"%newImageDir,"JPEG")
print '<html>'
print '''<img src="http://localhost/img/%s/hai.jpg">'''%dirnm
print '</html>'