Python论坛  - 讨论区

标题:[python-chinese] mod_python如何处理上传文件?

2005年04月19日 星期二 16:16

清风 baoogle at 126.com
Tue Apr 19 16:16:04 HKT 2005

file = req.form["myfile"].file
这样似乎不行,得到的是一个而不是FileType?


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年04月19日 星期二 16:25

fla liu fla.liu at gmail.com
Tue Apr 19 16:25:18 HKT 2005

mod_python 3.1.3 版本不能正确upload file 的解决办法 
   
   - 
   
   打开 util.py 文件,大概在 220 行 修改为 : 
   
    def __getitem__(self, key):
        """Dictionary style indexing."""
        if self.list is None:
            raise TypeError, "not indexable"
        found = []
        for item in self.list:
            if item.name <http://item.name> == key:
                if isinstance(item.file, FileType) or \
                       isinstance(getattr(item.file, 'file', None), FileType):
                    found.append(item)
                else:
                    found.append(StringField(item.value))
        if not found:
            raise KeyError, key
        if len(found) == 1:
            return found[0]
        else:
            return found



On 4/19/05, 清风 <baoogle at 126.com> wrote: 
> 
> file = req.form["myfile"].file
> 这样似乎不行,得到的是一个而不是FileType?
> 
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050419/86b667b3/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年04月19日 星期二 16:32

清风 baoogle at 126.com
Tue Apr 19 16:32:30 HKT 2005

fla liu 写道:

> mod_python 3.1.3 版本不能正确upload file 的解决办法
>
>    *
>
>       打开 util.py 文件,大概在 220 行 修改为 :
>
>    def __getitem__(self, key):
>        """Dictionary style indexing."""
>        if self.list is None:
>            raise TypeError, "not indexable"
>        found = []
>        for item in self.list:
>            if item.name <http://item.name> == key:
>                if isinstance(item.file, FileType) or \
>                       isinstance(getattr(item.file, 'file', None), FileType):
>                    found.append(item)
>                else:
>                    found.append(StringField(item.value))
>        if not found:
>            raise KeyError, key
>        if len(found) == 1:
>            return found[0]
>        else:
>            return found
>  
>
>
>
> On 4/19/05, *清风* <baoogle at 126.com baoogle at 126.com>> wrote:
>
>     file = req.form["myfile"].file
>     这样似乎不行,得到的是一个而不是FileType?
>
>     _______________________________________________
>     python-chinese list
>     python-chinese at lists.python.cn python-chinese at lists.python.cn>
>     http://python.cn/mailman/listinfo/python-chinese
>
>

这我改了呀,得到的是一个类型?

isinstance(getattr(item.file, 'file', None), FileType):
就加上这个是吧



[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年04月19日 星期二 16:35

Frank gavin at sz.net.cn
Tue Apr 19 16:35:04 HKT 2005

def upLoad_File(Attachments,tempDir=UPLOADDIR,MaxFileSize=5*Mb):
    uploaded=[]
    attached=[]
    error=''
    if type(Attachments)==type(''):
       attached.append(Attachments)
    else:
       attached=Attachments

    for n in range(len(attached)):
        Ln=0
        if  attached[n]:
            up_fd=attached[n].file
            filename=attached[n].filename
            if not filename.strip():continue
            filename=os.path.basename(filename).split("\\")[-1]
            out_filename=os.path.join(tempDir,filename)
            writelog(out_filename)
            out_fd = open(out_filename,"w+")
            for ln in up_fd.xreadlines():
                out_fd.write(ln)
                Ln += len(ln)
                if Ln>MaxFileSize:
                    error="文件太大,超过系统限制!"
                    os.remove(out_filename)
                    writelog(error+":%s\r\n"%filename)
                    break
            out_fd.close()
            up_fd.close()
            if error: break
            writelog("uploaded:%s"%out_filename)
            uploaded.append(filename)

    return error,uploaded

if form.has_key("Attachment"):
          att=form["Attachment"]
          error_msg,Attachments=upLoad_File(att,tempDir=UpLoadDIR,MaxFileSize=5*Mb)

文件将会存入指定目录中,上传的文件名在Attachments中

----- Original Message ----- 
From: "清风" <baoogle at 126.com>
To: <python-chinese at lists.python.cn>
Sent: Tuesday, April 19, 2005 4:16 PM
Subject: [python-chinese] mod_python如何处理上传文件?


file = req.form["myfile"].file
这样似乎不行,得到的是一个而不是FileType?

_______________________________________________
python-chinese list
python-chinese at lists.python.cn
http://python.cn/mailman/listinfo/python-chinese

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年04月20日 星期三 09:34

清风 baoogle at 126.com
Wed Apr 20 09:34:21 HKT 2005

Frank 写道:

>def upLoad_File(Attachments,tempDir=UPLOADDIR,MaxFileSize=5*Mb):
>    uploaded=[]
>    attached=[]
>    error=''
>    if type(Attachments)==type(''):
>       attached.append(Attachments)
>    else:
>       attached=Attachments
>
>    for n in range(len(attached)):
>        Ln=0
>        if  attached[n]:
>            up_fd=attached[n].file
>            filename=attached[n].filename
>            if not filename.strip():continue
>            filename=os.path.basename(filename).split("\\")[-1]
>            out_filename=os.path.join(tempDir,filename)
>            writelog(out_filename)
>            out_fd = open(out_filename,"w+")
>            for ln in up_fd.xreadlines():
>                out_fd.write(ln)
>                Ln += len(ln)
>                if Ln>MaxFileSize:
>                    error="文件太大,超过系统限制!"
>                    os.remove(out_filename)
>                    writelog(error+":%s\r\n"%filename)
>                    break
>            out_fd.close()
>            up_fd.close()
>            if error: break
>            writelog("uploaded:%s"%out_filename)
>            uploaded.append(filename)
>
>    return error,uploaded
>
>if form.has_key("Attachment"):
>          att=form["Attachment"]
>          error_msg,Attachments=upLoad_File(att,tempDir=UpLoadDIR,MaxFileSize=5*Mb)
>
>文件将会存入指定目录中,上传的文件名在Attachments中
>
>----- Original Message ----- 
>From: "清风" <baoogle at 126.com>
>To: <python-chinese at lists.python.cn>
>Sent: Tuesday, April 19, 2005 4:16 PM
>Subject: [python-chinese] mod_python如何处理上传文件?
>
>
>file = req.form["myfile"].file
>这样似乎不行,得到的是一个而不是FileType?
>
>_______________________________________________
>python-chinese list
>python-chinese at lists.python.cn
>http://python.cn/mailman/listinfo/python-chinese
>  
>
非常感谢:)


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号