Uploading files using (CGI)

I write a CGI applications using Delphi and I want to upload files to CGI server from the client (Internet Explorer) how can I do that?

Motaz
LVL 7
MotazAsked:
Who is Participating?
 
deroverConnect With a Mentor Commented:
Sorry, i seemed to have cut some important text :)  Here's the working one ":)


<html><body>upload ....<br>
<FORM ENCTYPE="multipart/form-data" ACTION="http://myserver/mycgi" METHOD=POST name=somename>
<INPUT TYPE="FILE" NAME="FILE1">
<INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="OK">
<INPUT TYPE="RESET" NAME="Reset" VALUE="Reset">
</FORM>
</body>
</html>



-Rover  
derover@xs4all.nl
http://www.xs4all.nl/~derover
0
 
intheCommented:
Hi Motaz
are you using webmodule then you could drop a ftp component to it..do you want that the user selects the files to send.
0
 
MotazAuthor Commented:
Yes I use WebModule, and yes I want the users to select the files from their hard disk then upload it in my site,

Did you mean that I need an FTP server?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
intheCommented:
>>FTP server
no..no.. i just think i have a demo of this or something similar at home,might be  sending a user selected graphic to a server i have too have a look later..
0
 
yk030299Commented:
listen
0
 
deroverCommented:
the "client"-side html form:

<html><body>select a file to upload ....<br>
<FORM ENCTYPE="multipart/form-data" ACTION="http://yourserversIP/yourCGIdirectory/yourupload.dll" METHOD=POST name=myfile>
</FORM>
</body>
</html>


Since you're already using the webmodule, i asumme you know how to read this. If not, please post the question "how do i read from WebModules" or something :)


0
 
MotazAuthor Commented:
Adjusted points to 100
0
 
MotazAuthor Commented:
What did you mean by YourUpload.dll did I need any DLL to upload files, and how can I let the user select files from his hard disk.

Sorry I'm new in CGI and WebModules

Motaz
0
 
deroverCommented:
the piece of html i posted before, will let users select files from their harddisk. (just try it, copy/paste the html in a temp html file, and double click it :)

With YourUpload.dll i meant an ISAPI/NSAPI dll.... but thats not what you are using i guess... you prolly selected WINCGI or Standalone CGI. Thats ok too, it will just have another extension (.exe). So then it would be YourUpload.exe ... (f.e. if your application is named "upload.dpr", it will compile to upload.exe... then the url would be something like ..../cgi-bin/upload.exe)

As for the code in your cgi : you can use TCGIRequest(Request).ReadClient to read whats been uploaded. Note: put "cgiapp" in your uses clause.



procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
  TCGIRequest(Request).ReadClient(......
end;



NOTE: Experts Exchange memo box might wrap the sentences.


Rover
0
 
MotazAuthor Commented:
derover, the client side didn't work, how can I make the user select file from his harddisk and upload it to my site.

Motaz
0
 
MotazAuthor Commented:
Ok it works, but after that how can I read the file, or save it in the server?
0
 
deroverCommented:
please ask this in a new question, so others can lurk and learn from it too. You dont have to give points to me, since i wont use those.

-Rover
derover@xs4all.nl
0
 
deroverCommented:
derover changed the proposed answer to a comment
0
 
MotazAuthor Commented:
Why not to tell me here, the people still gain the benefit here.
Please answer me here

Motaz
www.geocities.com/motaz1
0
 
deroverCommented:
I'm sorry, i somehow thought u already accepted the answer, and nobody (xcept for the ppl already listening :) could then see the stuff anymore. Anyway, here it is (i'm assumming u r using ISAPI here in this example code) :

u need to declare the VARs :

var
  ECB: PEXTENSION_CONTROL_BLOCK;
  buffer: array[0..1023] of char;
  len:integer;


Then in the webaction, u can do this :

  ECB:=(request as TISAPIRequest).ecb;
  len:=sizeof(buffer);

Then u can use
  ReadClient(ECB.ConnID, @Buffer, len);

to read the uploaded data
0
 
MotazAuthor Commented:
Unfortunately I use Stand alone CGI

0
 
deroverCommented:
same thing.... i think...

ECB:=(request as TCGIRequest).ecb  ??
0
 
deroverCommented:
i'm sorry, i forgot to say u've gotta "uses" CGIApp...

Then u can use
  TCGIRequest(Request).ReadClient

to read ... Hope this does actually help :)


-Rover
derover@xs4all.nl
0
 
MotazAuthor Commented:
Sorry derover, but that didn't work, you sent to me an ISapi example.
I want to to sent to me a complete sample of displaying uploaded text file in user browser, for example if the user upload a file I want to show file's content in:

Response.Content

I use STAND-ALONE CGI

Please test it befor sending it to me.


Motaz
0
 
deroverCommented:
If u take a look in the help of ReadClient, u'll see ReadClient is used after the data becomes too big for the Content var to hold it. So i guess u have to use

SomeBuf:=TCGIRequest(Request).Content;


Then u can use ReadClient/ReadString
0
All Courses

From novice to tech pro — start learning today.