12-31-2011 11:56 AM
**i am using the <h1>below code for uploading file (php + java code). but it’s not uploading.</h1>**
1. file is present in card(simulator) i check it via file explorer demo .
2. i tried to write text file when it hit the page but it’s not writing.
3. I have taken the code of file upload from another site. But can’t able to use .
So please share any code or remove error from the bellow code.
Thanks in advance
/******************Black Berry Java Code ******************/
package mypackage;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.io.file.FileConnection;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
public final class MyScreen extends MainScreen
{
public MyScreen() throws IOException
{
synchronized (UiApplication.getEventLock()) {
uplaod_file();
}
}
public void uplaod_file() throws IOException{
HttpConnection httpConn = (HttpConnection) Connector.open("http://localhost/upload/upload_fil
FileConnection fileConn = (FileConnection) Connector.open("file:///SDCard/n.txt");
InputStream in = fileConn.openInputStream();
OutputStream out = httpConn.openOutputStream();
byte[] buffer = new byte[1000];
int bytesRead = 0;
bytesRead=in.read(buffer);
while((bytesRead) > 0)
{
out.write(buffer, 0, bytesRead);
}
}
}
/****************** Php code****************** /
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
/*-File writeing check*/
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, "that");
fclose($fh);
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
?>
01-02-2012 05:31 AM
Hi,
maybe you testing the Extension "FileUpload" from github?
https://github.com/blackberry/WebWorks-Community-A
cu
UserNeo