]> bicyclesonthemoon.info Git - ott/enhance/commitdiff
Let's upload something!
authorb <b@0d794883-4e4e-4f65-aa7a-0e7f5947bab5>
Tue, 31 Dec 2013 17:42:29 +0000 (17:42 +0000)
committerb <b@0d794883-4e4e-4f65-aa7a-0e7f5947bab5>
Tue, 31 Dec 2013 17:42:29 +0000 (17:42 +0000)
git-svn-id: svn://botcastle1b/npb@22 0d794883-4e4e-4f65-aa7a-0e7f5947bab5

npb.htm
npbd
npbd.cpp

diff --git a/npb.htm b/npb.htm
index b137293f5941359a7d8e683fa65c78578232f215..8dbf692f5a705abfa5572b0f6dcb10ec284af56d 100644 (file)
--- a/npb.htm
+++ b/npb.htm
@@ -8,10 +8,17 @@
                <h1>It's NewpixbOTTification time!</h1>
                <form method="get" action="/cgi/npb/npbd">
                        NewpixbOTTify by URL<br>
-                       URL:
-                       <input type="text" name="inpix" value="http://">
+                       URL of image:
+                       <input type="text" name="inpix">
                        <input type="submit" value="NewpixbOTTify!">
                </form>
                Please don't hotlink the result. If you do, each time someone sees your link, my server will have to generate the image again!
+               <br><br>
+               <form method="post" action="/cgi/npb/npbd" enctype="multipart/form-data">
+                       NewpixbOTTify by file upload<br>
+                       Upload the image:
+                       <input type="file" name="inpix">
+                       <input type="submit" value="NewpixbOTTify!">
+               </form>
        </body>
 </html>
diff --git a/npbd b/npbd
index 9fc150e4027e4f21a1479e4728377cb7c51a8f6e..b0a9d9032517e131b0cd9a1feecf350446282d51 100755 (executable)
Binary files a/npbd and b/npbd differ
index ea09373fb1d49bff0cb7f546d235d705c7c364f9..0fa22889ab67e26fc2fea489eb598af1f631dd17 100644 (file)
--- a/npbd.cpp
+++ b/npbd.cpp
@@ -12,6 +12,7 @@
 #include <cgi.h>
 #include <stdio.h>
 #include <stdlib.h>
+//#include <strings.h>
 #include <unistd.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
@@ -28,31 +29,40 @@ FILE *pix;
 unsigned char buf[1024];
 char url[1024];
 char path[256];
-//char cmd[1024];
+char method[256];
 s_cgi *cgi;
 int t;
 pid_t sub;
 struct stat st;
 unsigned long p;
 unsigned short q;
+char **up;
 
 int main (int argc, char *argv[])
 {
-       
        cgi=cgiInit();
-       sprintf(url,"%s",cgiGetValue(cgi,"inpix"));
-       sprintf(path,"/var/tmp/%lu",(unsigned long)getpid());
-       
        
-       //Why is  there no spawnl() in linux?
-       sub=fork();
-       if(sub==0)
+       up=cgiGetFiles(cgi);
+       if (up)
        {
-               t=execl(WGET_PATH,WGET_PATH,"-q","-O",path,url,(char *)0);
-               exit(t);
+               sprintf(path,"%s",cgiGetFile(cgi,up[0])->tmpfile);
+               sprintf(url,"%s",cgiGetFile(cgi,up[0])->filename);
+       }
+       else
+       {
+               sprintf(url,"%s",(cgiGetValue(cgi,"inpix")!=NULL)?(cgiGetValue(cgi,"inpix")):"");
+               sprintf(path,"/var/tmp/%lu",(unsigned long)getpid());
+               
+               //Why is  there no spawnl() in linux?
+               sub=fork();
+               if(sub==0)
+               {
+                       t=execl(WGET_PATH,WGET_PATH,"-q","-O",path,url,(char *)0);
+                       exit(t);
+               }
+               waitpid(sub,&t,0);
+               if(t)mustard(t);
        }
-       waitpid(sub,&t,0);
-       if(t)mustard(t);
        
        sub=fork();
        if(sub==0)