Get images or binary files from web form

new topic     » topic index » view thread      » older message » newer message

Hello all!

I am trying to do an web form where the people send me some text fields and 2 or 3 photos.

How can a cgi-bin to process this? I can get successly text files, but binary files don't work. (XAMPP on Windows 7 machine).

Any hint?

This is my first experiment:

<html><head></head><body> 
 
<form method="post" action="/cgi-bin/prueba.cgi" enctype="multipart/form-data"> 
	Your text: <input name="primero" /> 
	<br>	 
	Your file: <input type="file" name="imagen" accept="image/png, .jpeg, .jpg, image/gif"> 
	<br> 
	<input type="submit" /> 
</form> 
 
</body></html> 
 

This is the prueba.cgi, based on cgitest file I have take and modified from examples on the archive:

#!eui 
-- test program for euphoria cgi 
-- comment/uncomment the following to test the EUINC variable 
 
with batch 
 
include std/io.e 
include std/pretty.e 
sequence cmd 
 
-- if val is a string, return it, otherwise "Undefined" 
function test_val(object val) 
    if atom(val) then 
        return "Undefined" 
    elsif object(val) then 
        for i = 1 to length(val) do 
            if not atom(val[i]) then 
                return "Invalid string sequence" 
            end if 
        end for 
        return val 
    else 
        return "Invalid type for string" 
    end if 
    return "foozle" -- never reached 
end function 
 
 
procedure env_dump(sequence val) 
     printf(1, "%s: %s\n", {val, test_val(getenv(val))} ) 
end procedure 
 
puts(1, "Content-Type: text/plain\n\n") 
puts(1, "Hello!\n\n") 
puts(1, "COMMAND LINE\n============\n\n") 
 
cmd = command_line() 
for i = 1 to length(cmd) do 
    printf(1, "%d: %s\n", {i, cmd[i]} ) 
end for 
 
puts(1, "\n\nREMOTE INFO\n===========\n") 
 
env_dump("REMOTE_IDENT") 
env_dump("REMOTE_USER") 
env_dump("REMOTE_HOST") 
env_dump("REMOTE_ADDR") 
 
puts(1, "\n\nSERVER INFO\n===========\n") 
env_dump("SERVER_SOFTWARE") 
env_dump("SERVER_NAME") 
env_dump("GATEWAY_INTERFACE") 
env_dump("SERVER_PROTOCOL") 
env_dump("SERVER_PORT") 
env_dump("REQUEST_METHOD") 
env_dump("PATH_INFO") 
env_dump("PATH_TRANSLATED") 
env_dump("SCRIPT_NAME") 
env_dump("QUERY_STRING") 
env_dump("AUTH_TYPE") 
env_dump("CONTENT_TYPE") 
env_dump("CONTENT_LENGTH") 
 
puts(1, "\n\nBROWSER INFO\n============\n") 
env_dump("HTTP_ACCEPT") 
env_dump("HTTP_USER_AGENT") 
 
puts(1, "\n\nSTANDAR INPUT\n=============\n") 
sequence whole_file 
whole_file = {} 
sequence chunk 
while 1 do 
	chunk = get_bytes(0, 1024) -- read 100 bytes at a time 
	whole_file &= chunk 
	-- chunk might be empty, that's ok 
	if length(chunk) < 1024 then 
		exit 
	end if 
end while 
 
print(1, whole_file) 
printf(1, "\n\nEl archivo recibido tiene %d bytes\n\n", {length(whole_file)}) 
-- should match DIR size of "temp" 
 
puts(1, whole_file) 
new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu