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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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
deroverCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.