ok, first of all: inside my processing script i have these script for saving:
void keyReleased () {
switch (key) {
case 's':
saveToWeb_saveJPG("processing",true, get(0,0,width-175,height));
break;
}
}
in a second file i have this script:
import com.sun.image.codec.jpeg.*;
String url = "http://leanderlike.com/processing"; // i put the correct url inside it
boolean saving = false;
void saveToWeb_saveFile(String title, String ext, String folder, byte[] data, boolean popup)
{
println("SAVING File START");
postData(title+"_"+aZ(year())+aZ(month())+aZ(day())+"-"+aZ(hour())+aZ(minute())+
aZ(second()),ext,folder,data,popup);
println("SAVING File STOP");
}
void saveToWeb_saveJPG(String title, boolean date, PImage src)
{
println("SAVING JPG START");
postData(title+((date)?"_"+aZ(year())+aZ(month())+aZ(day())+"-"+aZ(hour())+aZ(mi
nute())+aZ(second()):""),"jpg","saved",bufferImage(src),true);
println("SAVING JPG STOP");
}
void postData(String title, String ext, String folder, byte[] bytes, boolean popup)
{
try{
URL u = new URL(url+"saveFile.php?title="+title+"&ext="+ext+"&folder="+folder);
URLConnection c = u.openConnection();
// post multipart data
c.setDoOutput(true);
c.setDoInput(true);
c.setUseCaches(false);
// set request headers
c.setRequestProperty("Content-Type", "multipart/form-data; boundary=AXi93A");
// open a stream which can write to the url
DataOutputStream dstream = new DataOutputStream(c.getOutputStream());
// write content to the server, begin with the tag that says a content element is comming
dstream.writeBytes("--AXi93A\r\n");
// discribe the content
dstream.writeBytes("Content-Disposition: form-data; name=\"data\"; filename=\"whatever\" \r\nContent-Type: image/jpeg\r\nContent-Transfer-Encoding: binary\r\n\r\n");
dstream.write(bytes,0,bytes.length);
// close the multipart form request
dstream.writeBytes("\r\n--AXi93A--\r\n\r\n");
dstream.flush();
dstream.close();
// read the output from the URL
try{
DataInputStream in =
new DataInputStream(
new BufferedInputStream(c.getInputStream()));
String sIn = in.readLine();
boolean b = true;
while(sIn!=null){
if(sIn!=null){
if(popup) if(sIn.substring(0,folder.length()).equals(folder)) link(url+sIn, "_blank");
System.out.println(sIn);
}
sIn = in.readLine();
}
}
catch(Exception e){
e.printStackTrace();
}
}
catch(Exception e){
e.printStackTrace();
}
}
String aZ(int v)
{
if(v<10) return "0"+v;
return ""+v;
}
byte[] bufferImage(PImage srcimg){
ByteArrayOutputStream out = new ByteArrayOutputStream();
BufferedImage img = new BufferedImage(srcimg.width, srcimg.height, 2);
img = (BufferedImage)createImage(srcimg.width, srcimg.height);
for(int i = 0; i < srcimg.width; i++)
{
for(int j = 0; j < srcimg.height; j++)
{
int id = j*srcimg.width+i;
img.setRGB(i,j, srcimg.pixels[id]);
}
}
try{
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam encpar = encoder.getDefaultJPEGEncodeParam(img);
encpar.setQuality(1,false); // 0.0-1.0, force baseline (?)
encoder.setJPEGEncodeParam(encpar);
encoder.encode(img);
}
catch(FileNotFoundException e){
System.out.println(e);
}
catch(IOException ioe){
System.out.println(ioe);
}
return out.toByteArray();
}
On my server i put a folder called"processing" my script stuff from processing (the applets) and a folder called "saved" and a saveFile.php file. inside the saveFile.php - file is this script
<?
$Title = $_GET['title'];
$Ext = $_GET['ext'];
$folder = $_GET['folder'];
$savepath = dirname($_SERVER["PATH_TRANSLATED"]);
$filename = $Title.".".$Ext;
while(file_exists($folder."/".$filename))
$filename = $Title."-".rand(2,500).".".$Ext;
if (is_uploaded_file($data))
{
$newfile = $savepath."/".$folder."/".$filename;
if (!copy($data, $newfile))
{
// if an error occurs the file could not
// be written, read or possibly does not exist
echo "Error #1 Uploading File.";
exit();
}else{
echo $folder."/".$filename;
}
}else{
echo "Error #2 Uploading File.";
exit();
}
?>
I did not change anything in that last code script.
still not working
BTW: when talking about the popup -> look at this site. when saving the image a new window pops up. http://wliia.org/projects/spiro/
What sort of script do i have to use to show all uploaded images on one page? as you mentioned in your last sentence?
i'm sorry, i don't have any knowledge of php, but i hope we get it fixed anyway. thanks a lot for your help!!!!!!!