请问如何在Web页中实现文件的上载?(200分)

  • 主题发起人 主题发起人 yysun
  • 开始时间 开始时间
Y

yysun

Unregistered / Unconfirmed
GUEST, unregistred user!
在www.geocities.com的免费主页系统中,如要上载文件,只需在Web页的
表格中加入本地的文件名和路径,按一按钮,就能上载文件到Web服务器。
请教这个功能是不是由CGI实现?如何实现呢?
 
(200分! 好诱人哪!)
您需要使用CGI. 上传的原理是通过Form把文件按multipart/form-data格式编码传送给CGI程序, 然后再
由CGI程序解码后作相应处理(比如根据Form上填写的参数)
Form的定义例子如下
&ltform enctype="multipart/form-data" action="/cgi-bin/sw/upload.exe" method=post&gt
&ltinput name="filename" type="file" &gt
&ltinput type="submit" value="开始上传"&gt
&lt/form&gt
注意Method一定要用POST, 不能用GET, 因为GET方法
是通过环境变量传递数据给CGI程序的, 您当然不能指望
环境变量的存储空间可以容纳下大文件的内容

呵呵, 分这么多, 看来如果不写个服务端的CGI的例子,
yysun是不会善罢甘休的, :)
I'll go to writing, :)
 
我等着您的"服务端的CGI"呢,我的这个论坛有了它,大家可以自由上载答案
和例子了,免得老是通过Email传递.
先代表大家谢谢您了.

 
Hehe, I'm sorry that I have to go home during the National day.
See you aftand all Delphi Fans here after the holiday!

And thank you very much for building this forum!
 
Have a good holiday! Pegasus.
Looking forward to seeing you again.
 
正在努力中......, :(
虽说原理很简单,但是细节还是很多的, 而且这个方法是
HTML4.0中才有的, 我手头的很多库程序都不支持, 必须自己
来做.
(PS: IE3.0不支持, Netscape 3.0, IE4.0 已经支持)
 
费了半天劲, 离成功还远着呢, :(~~~
休息一下, 上网逛一逛, :)
咦? What's that? Free software from WebCom, Em, let's
go to have a look

Ohh, my dear! Upload script, that the only one I need!
What, a plug-in makes IE3.02 support upload, that's nice!

D/l then check it,

文档齐全, 考虑周到, 性能不错...

哈哈, 得来全不费功夫.

不过我的劲也没有白费, 总算知道它有多么复杂, :)

I'll mail them to Master.

Have a rest, :)
 
Hi, pegasus,
受您启发,吾亦有所发现:
(http://liquid-sky.media.mit.edu/about_file_upload.html)
#include <iostream.h>
extern "C"
{#include <stdlib.h>}
void main(){
int content_length=strtoul(getenv("CONTENT_LENGTH"),(char**)0,10);
cout<<"Content-Type: text/plain"<<endl;
cout<<endl;
for (int i = 0; i < content_length; ++i)
cout.put(cin.get());
}


 
I am confused by your code., :)
It can't work for uploading file, :)
To upload a file using Browser, without
using a self-programmed program, (this
is convenient for common users)
We must build a cgi which can parse
"multipart/form-data" format data.

(If build own app to upload file, we
do not need "multipart/form-data anymore,
just using "PUT" method, then read file
content, transfer to Webserver)
因为我们要让浏览器能够上传, 所以不
能使用您提供的代码(这样的代码必须在
客户端运行)
 
sorry! pegasus, When I erntered the code with < and >, it was parsed by the BBS as HTML reservered symbol. You can view the source of this page to see the small CGI program. This program can get the file from the browser and can send back to the browser to display it.

I found this code at
http://liquid-sky.media.mit.edu/about_file_upload.html

I think that if this CGI program can get the file from stdin stream, we can find a Delphi decode(MIME ? I'm not sure) component which also
supports stream to save the file to disk.
 
Hehe, you can use '&' lt to replace &lt, :)
'&' gt to replace &gt

But that requires any user who want to upload files
to run a program at his machine. If so, why not using
a FTP?

OK?
 
That program is a CGI, not local program, I think.
 
当然, 上传的基本原理就是由CGI把Browser的数据解码还原成文
件的内容, 然后存盘. 但是普通的Form参数传递的方法不能传输
文件的内容,而只能传递文件名, 只有根据RFC1867所提出的
MultiPart/Form-Data的方式, 让用户输入文件名, 浏览器依照该标
准选择某种编码方式把文件的名字和内容传给WebServer. CGI
就可以从中得知文件名和文件内容, 并根据其他参数所设定的
值决定如何存放上传的文件. (总想提供一些灵活性吧, :)

您所贴出的代码, 只是CGI工作的基本原理, 要想做成好用的上
传CGI, 还用很多工作要做. 不瞒您说, 我本来想自己解决, 但因
为手头的编解码库都没有适合RFC1867的, 又看到我提到的Free
CGI为Upload CGI的源码开出了500$的价格(大部分其他源码都是
免费的!), 所以知道这一定不是一件容易的事, 为了不耽误大家
上传, 也为了不浪费资源, 我就... Xixi, :)

BTW, 我昨天寄给您的上传CGI被退回来了, 但是邮件服务器说
会在五天内不断重试发送, 不知您是否已经收到, 另外, 因为
Visual Prolog实在太大, 是否用ARJ分解之后寄出?

 
是啊,我知道问题就在解码方面了。

ps.上传CGI尚未受到,正在恭候中 ...
您能帮我分解Visual Prolog,真是麻烦您了,非常感谢!
 
嗨呦, 这200分可真难赚, :): 这不, All my mail to yysun@nt4.gislab.ecnu.edu.cn were
refused, :(
Error string:
I/O error.
Is that too large?
I send them in 1.5M thunk.

How can I send them to you?
 
我不大清楚Email有什么问题,今早,smille的虾还传来5M的内容。

分数可以先加上,没有问题了。
 
后退
顶部