HardBirch

如何使用Mason来实现文件上传

时间:10-04-16 栏目:HTML5移动开发 作者:张飞不张,文采横飞 评论:0 点击: 1,336 次

The basic HTML for an upload form looks like:

 

The way you handle the submission depends on which args method you chose for the ApacheHandler class.
Under the 'CGI' method (default for 1.0x), you can use the $m->cgi_object method to retrieve a CGI.pm object which can be used to retrieve the uploaded file. Here is an example using the 'CGI' method:

 

 

Please see the CGI.pm documentation for more details.
Under the 'mod_perl' method (default for 1.1x), the request object available as $r in your components will be an object in the Apache::Request class (as opposed to the Apache class). This object is capable of returning Apache::Upload objects for parameters which were file uploads. Please see the Apache::Request documentation for more details. Here is an example using the 'mod_perl' method:

 

 

For more information on how to manually set the args method, see the ApacheHandler documentation.
If you are using CGI.pm, there are some configuration issues to be aware of. CGI.pm needs a tmp directory, and you probably want to be able to specify what that directory is.
Try doing this in your httpd.conf or handler.pl:

 

 

You must do this before you load either the HTML::Mason or HTML::Mason::ApacheHandler modules.
That may change which directories CGI tries to use.
You could also try

 

 

during startup, either in your httpd.conf or handler.pl
The root of the problem is probably that the temp directory is being chosen when the module loads uring server startup while its still root. It sees it can write to /usr/tmp and is happy. Then when actually running as nobody it dies.
I bet Lincoln would welcome a patch (hint, hint). One solution would be to check if you're running under mod_perl and you're root. If so, then check Apache->server->uid and see if that id can write to the temp directory too.

两种方法中,当然使用mod_perl为佳,cgi的实现方式还需要写缓存文件,如果磁盘空间不足,则会出现无法上传的情况。

 

一个使用的实例:http://passport.maxthon.cn/new/myprofile/avatar.html

 

引自:http://www.masonhq.com/?FAQ:HTTPAndHTML#h-how_can_i_handle_file_uploads_under_mason

声明: 本文由( 张飞不张,文采横飞 )原创编译,转载请保留链接: 如何使用Mason来实现文件上传

如何使用Mason来实现文件上传:等您坐沙发呢!

发表评论


QQ群互动

Linux系统与内核学习群:194051772

WP建站技术学习交流群:194062106

魔豆之路QR

魔豆的Linux内核之路

魔豆的Linux内核之路

优秀工程师当看优秀书籍

优秀程序员,要看优秀书!

赞助商广告

友荐云推荐