FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Integration
(Moderators: fry, REAS)
   processing and php?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: processing and php?  (Read 4160 times)
azarimy

WWW Email
processing and php?
« on: Jul 26th, 2004, 12:45pm »

hi, i'm very, very new to processing, and basically have very little programming skills (some html, basic javascript, basic vrml, basic c++). right now i'm doing a project that needs to integrate an applet with a php forum (specifically invisionboard).
 
here's the forum board: http://www.tanggam.com
and here's the applet: http://azarimy.50free.net/sketchrep/
 
what i wanted to do is to have the applet to be integrated in the forum reply dialog. right now i'm trying to finish the applet (which by the way is a sketchpad, basically introducing graphic/drawings into a text dominated discussionboard).  
 
some problems:
 
i. can i get users to upload their own images to the applet so they could sketch or scribble something on the image?
ii. can i then post the scribbled image into the forum?
 
i wish to know this, and any kind of help or reference would be much appreciated.
 
fjen

WWW
Re: processing and php?
« Reply #1 on: Jul 26th, 2004, 2:14pm »

question 1:
 
a small example (image from url other than applet server) is here:
http://www.florianjenett.de/p55/img_from_user_url/
 
no upload though. ... and it's quite slow.
 
there are plenty of upload scripts (PHP) on the net. it's not that difficult to modify these to get you started. the main problem might be to secure things ... that's why i prefer to let people upload to their own space and provide the image-url to the applet.
 
fjen

WWW
Re: processing and php?
« Reply #2 on: Jul 26th, 2004, 6:07pm »

question 2:
 
this is a general problem when running as (unsigned) applet. save(), saveFrame() don't work and using "normal" java you're neither allowed to save files to the server nor to the client for security reasons.
see:
http://www.developer.com/java/article.php/934031
 
but ...
you could do a file-post to PHP using a http-socket from within the applet. i've been looking into that and will post an example here soon.
 
TomC

WWW
Re: processing and php?
« Reply #3 on: Jul 26th, 2004, 11:37pm »

Hi Azari - good to see you here!
 
Just some pointers for people trying to save images from an applet back to the server.
 
Firstly, you're going to need to find the relevant server-side code (PHP, Perl, whatever) to receive an image by http (this is done as a multipart/form POST message IIRC).  There's plenty of code out there which will help you do this and save, display, or write it into a database, depending on your needs.
 
Secondly, I think fjen is right about needing to make an http POST request from the applet in order to send an image to a server.  You might like to look at the Apache Jakarta Commons project, particularly the httpclient package, to help you do this - it has a multipartpost object which should do what you want http://jakarta.apache.org/commons/httpclient/methods/multipartpost.html
 
Thirdly, you will either be sending uncompressed images (if you use the raw pixels from a BImage), or you will need to work out how to encode an image whilst it's in memory.  That might be tricky, I don't know.
 
To tie it all together with a discussion forum will be tough though - perhaps you could use some javascript to post the image from the applet, and then add the image location to the forum form and post that.  Not sure how to do it in one go though.
 
Good luck!
« Last Edit: Jul 27th, 2004, 12:08pm by TomC »  
fjen

WWW
Re: processing and php?
« Reply #4 on: Jul 27th, 2004, 10:51am »

i second tom's reply.
 
here's a quick example (read image from url && post image to server). needs some cleaning and is not really a beauty, but might get you started.
http://www.florianjenett.de/p55/socket_image/
 
best, F
 
Euskadi


Re: processing and php?
« Reply #5 on: Aug 6th, 2004, 3:29am »

fjen, your example works for me fine through your page. very cool!
 
what I'm trying to do is send name/data pairs through post to my server -- I can't figure out the magic combination to change your code to fit what I want to do. can you help?
 
I want to send name="bulk" value = "kjakjfjadsfdff ... really long string ...  ddddddfdkljflasjf"
 
fjen

WWW
Re: processing and php?
« Reply #6 on: Aug 6th, 2004, 9:04am »

(1)
in the sketch (socket_image.pde) there is the line: Code:
poststring += param[i] + "=" + value[i];
this is actualy name=value ... just change the contents to fit your needs.
 
(2)
in the top part of file_receive.php the variables are read from post: Code:
$width  = $_POST['width'];
      $height = $_POST['height'];
      $pixels = $_POST['pixels'];

you need to change this to fit your names (param array in the sketch) ... then you can work with them from there on - you will need to write you own php code for saving the file then.
 
maybe you wanna send some link / code so i could help you more specific.
« Last Edit: Aug 6th, 2004, 9:06am by fjen »  
Euskadi


Re: processing and php?
« Reply #7 on: Aug 14th, 2004, 4:34am »

I DID IT!  Sorry, fjen, I tried and tried but your method didn't work for me. I was probably sitting facing the wrong direction, I have bad luck like that.
 
Anyway, I found another way... instantly drops 1500 random values into my MySQL database (through POST to PHP). I'm not going to send a sample, that last thing I need is a lot more random data.
 
Briefly, I did it this way... I found this code....
 
http://www.devdaily.com/java/edu/pj/pj010023/index.shtml
 
Code:

void postNewItem () {  
  try {  
 
    URL      url;  
    URLConnection urlConn;  
    DataOutputStream   dos;  
    DataInputStream    dis;  
 
    url = new URL("http://www.fictionalsite.com/dir/catcher.php");  
    urlConn = url.openConnection();  
    urlConn.setDoInput(true);  
    urlConn.setDoOutput(true);  
    urlConn.setUseCaches(false);  
    urlConn.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded");  
 
    dos = new DataOutputStream (urlConn.getOutputStream());  
 
//added this to dump a bunch of data at the server
    String message="vals=1500";
    float vv;
    for(int i=0; i<1500; i++){
    vv = random(0,2);
    message += "&i" + nf(i, 0);
    message += "=" + nf(vv, 1, 4);
    }
    dos.writeBytes(message);  
    dos.flush();  
    dos.close();  
 
    // the server responds by saying  
    // "SUCCESS" or "FAILURE"  
 
    dis = new DataInputStream(urlConn.getInputStream());  
    String s = dis.readLine();  
    dis.close();  
   
    if (s.equals("SUCCESS")) {  
 //toDoList.addItem(addTextField.getText());  
 ;//addTextField.setText("");  
    } else {  
 ; //addTextField.setText("Post Error!");  
    }  
 
  } // end of "try"  
 
  catch (MalformedURLException mue) {  
    ; //addTextField.setText("mue error");  
  }  
  catch (IOException ioe) {  
    ; //addTextField.setText("IO Exception");  
  }  
 
}  // end of postNewItem() method  
 

 
 
and i have this PHP page to catch the values and insert into the DB. slick!!!!
 
Code:

// cut cut cut
 $vals = $_POST['vals'];
 
 for($i=0; $i<$vals; $i++){
 
  $v = $_POST["i$i"] + 0;
  $values .= "('$i', '$v'),";
}
 
 
$values = substr($values, 0, strlen($values) -1);  
 
//$values = "(0, 0.3)";
 
      $link = mysql_connect ($inc_host, $inc_user, $inc_password) or die ("Can't connect to database!");
     mysql_select_db ($inc_database) or die ("Can't select database!");  
$query = "INSERT into sd_dumptwo (item, value) values $values";
$result = mysql_query ($query) or die("query failed : " . mysql_error());
$simid = mysql_insert_id();
 
// cut cut cut

 
fjen

WWW
Re: processing and php?
« Reply #8 on: Aug 14th, 2004, 8:45am »

cool. have you checked the integrity of your data? normaly going thru a POST/GET you have to URLencode things - otherwise some chars like "ÄÜÖ .." might get garbled.
 
i've been thinking about the image-encoding problem (big transfers). mixed some examples to get the BImage to be encoded as JPEG.
 
here it is:
forget about the main function ... important things are:
- mousereleased - where the image-encoding is called from
- and the JPEGEncoder class
 
http://www.florianjenett.de/p55/P_JPGEncoder.java
 
oh, btw.: it won't compile in the PEnvironment (Image-problem) ... but outside it works fine.
 
best /F
« Last Edit: Aug 14th, 2004, 6:10pm by fjen »  
Euskadi


Re: processing and php?
« Reply #9 on: Aug 14th, 2004, 5:28pm »

I'm creating a simulation and I'm going to use POST to dump occasional snapshots of what is going on, it's all numeric, so I don't expect any problems with data.
 
Pages: 1 

« Previous topic | Next topic »