How to upload file from java client to php
hi
i am trying to upload/send a file from client using swing/applet
and receiving it with php code.
here is the php code which uploads the post file from the client
$uploaddir = "/home/raghavendra/Documents/";
$file = basename( $_FILES["uploadedfile"]["name"]);
echo "file:\n".$file;
$uploadfile = $uploaddir. $file;
if (move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],$uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
else {
echo "File upload failure Possible file upload attack!\n";
and corresponding different java code which post the
1)
public void postmethodTest(String filefrom){
try{
String hostname = "localhost";
int port = 80;
InetAddress addr = InetAddress.getByName(hostname);
Socket socket = new Socket(addr, port);
// Send header
String path ="/php_prgs/var/www/nsboxng/htdocs/tryupdate.php";
File theFile = new File(filefrom);
System.out.println ("size: " + (int) theFile.length());
DataInputStream fis = new DataInputStream(new BufferedInputStream(new FileInputStream(theFile)));
byte[] theData = new byte[(int) theFile.length( )];
fis.readFully(theData);
fis.close();
DataOutputStream raw = new DataOutputStream(socket.getOutputStream());
Writer wr = new OutputStreamWriter(raw);
String command =
"POST "+path+" HTTP/1.0\r\n"
+ "Content-type: multipart/form-data, boundary=mango\r\n"
+ "Content-length: " + ((int) theFile.length()) + "\r\n"
+ "\r\n"
+ "--mango\r\n"
+ "content-disposition: name=\"MAX_FILE_SIZE\"\r\n"
+ "\r\n"
+ "\r\n--mango\r\n"
+ "content-disposition: attachment; name=\"datafile\"" ;
String filename="test.doc\"\r\n"
+ "Content-Type: text/doc\r\n"
+ "Content-Transfer-Encoding: binary\r\n"
+ "\r\n";
wr.write(command);
wr.flush();
raw.write(theData);
raw.flush( );
wr.write("\r\n--mango--\r\n");
wr.flush( );
BufferedReader rd = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println("out"+line);
wr.close();
raw.close();
socket.close();
} catch (Exception e) {System.out.println(e.toString());}
2)
public void postMethod(String strURL, String filefrom){
try {
String fname = filefrom.substring(filefrom.lastIndexOf("/")+1, filefrom.length());
File input=new File(filefrom);
// Prepare HTTP post
PostMethod post = new PostMethod(strURL);
// Request content will be retrieved directly
// from the input stream
// Per default, the request content needs to be buffered
// in order to determine its length.
// Request body buffering can be avoided when
// content length is explicitly specified
post.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(input), input.length()));
// Specify content type and encoding
// If content encoding is not explicitly specified
// ISO-8859-1 is assumed
//post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
post.setRequestHeader("Content-Type","multipart/form-data");
post.setRequestHeader("Content-Disposition", "form-data; name="+fname);
// Get HTTP client
HttpClient httpclient = new HttpClient();
// Execute request
try {
int result=httpclient.executeMethod(post);
// Display status code
System.out.println("Response status code: " +result);
// Display response
System.out.println("Response body: ");
// System.out.println(post.getResponseBodyAsString());
BufferedReader console = new BufferedReader(new InputStreamReader(post.getResponseBodyAsStream()));
String name = null;
String line = null;
try {
while ((line = console.readLine()) != null) {
System.out.println("output"+line);
//name = console.readLine();
catch (IOException e) { name = "<" + e + ">"; }
// System.out.println("Hello " + name);
} finally {
// Release current connection to the connection pool
// once you are done
post.releaseConnection();
catch(IOException e){
but am getting else condition response from php code
but if i post with html code it is working fine.
can anybody help me please where i have to change the code
please suggest me. am in a big trouble and i have to complete this as soon as possible
One thread is enough.
http://forum.java.sun.com/thread.jspa?threadID=5198449
You could have bumped it instead. Also, you still just posted a junk of unformatted stuff. Furthermore, for HttpClient support ask at an HttpClient mailing list of rorum.
Similar Messages
-
How to upload file from a client machine to server machine
hei evryone!
can anyone pls help me on how i can upload file from a client machine to another machine (or server). using jsp.Then later on, i can also retrieve the names of these files to place it as values for option tag in an html form.I have a seperate screen for uploading the file and the screen for displaying all the files that were uploaded on the server...
any sample code/ ideas would be much appreciated.Thx!!!!hei evryone!
can anyone pls help me on how i can upload file from a client machine to another machine (or server). using jsp.Then later on, i can also retrieve the names of these files to place it as values for option tag in an html form.I have a seperate screen for uploading the file and the screen for displaying all the files that were uploaded on the server...
any sample code/ ideas would be much appreciated.Thx!!!! -
How to upload file from Application Server?
Dear Friends,
How to upload file from Application Server?
Plz. with example...
Regards,
Dharmeshhi,
check the code for upload from application server.
tables: kna1.
types: begin of s_file,
customer type kna1-kunnr,
country type kna1-land1,
name type kna1-name1,
region type kna1-regio,
end of s_file.
*--Internal tables
data: it_file type s_file occurs 0 with header line.
*-- Selection screen
selection-screen: begin of block b1 with frame title text-001.
parameter: p_file type rlgrap-filename default 'C:/customer.txt'
obligatory.
selection-screen: end of block b1.
*-- At selection screen
at selection-screen on value-request for p_file.
perform file_help using p_file.
*-- Process File
start-of-selection.
perform upload_file using p_file.
*-- write File data to o/p
end-of-selection.
perform write_data.
*& Form file_help
form file_help using p_p_file.
data: l_filepath type ibipparms-path.
call function 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
importing
file_name = l_filepath
p_p_file = l_filepath.
endform. " file_help
*& Form upload_file
form upload_file using p_p_file.
call function 'WS_UPLOAD'
exporting
filename = p_p_file
filetype = 'DAT'
IMPORTING
FILELENGTH =
tables
data_tab = it_file
exceptions
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
no_authority = 10
others = 11
if sy-subrc <> 0.
message i001.
endif.
endform. " upload_file
*& Form write_data
form write_data .
loop at it_file.
write:/ it_file-customer, it_file-country, it_file-name,
it_file-region.
endloop.
endform.
regards,
keerthi. -
How to upload file from client to server in servlets.
actually in my application i have to upload file from client m/c to server.
it is not possible through file i/p stream as fileStreams does not work on network. Please mail me if you have any solution to this.
Thank's in advance............Haii roshan
Pls go through this thread..
http://forum.java.sun.com/thread.jspa?forumID=45&threadID=616589
regards
Shanu -
How to transfer file from one client to another client?
hello,
i have some questions and hope you all can help me..thanks a lot first..
Here are the questions:
i) How can i send a file from one client to another client using RMI?
ii) Does the client(sender) need to send the file to server, then server save it and then send it to another client(receiver)?
iii) If using RMI, a client can receive two files from same client(sender) or different client(sender) at a same time? how to do it? when both of the files come in from same port, how to differenciate them?
iv) For your information, i am doing the File Transfer Server-client application which sender can send any file to other client. Can you give me any ideas? thanks..
Last, thanks again..Your questions reflect some ambiguity in terms.
"Client" and "server" are commonly used in two different senses:
1. Technical sense: A client process makes requests, and a server process fulfills the request (provides a service).
2. IT sense: A client computer (process) makes requests of a server (computer) process, and the server (computer) processes the request.
In the first case, any computer might be a client, or a server, or both, depending on the processes being executed. In the second case, the computers are assigned some role.
So: If you wanted to, you could implement client/server processes communicating between two peer computers, using RMI.
This may not be what you wanted; if you really want to distinguish client and server computers, then the answer is that yes, you will probably put files into intermediate storage on the server computer.
Finally, you probably do not have to worry about port conflicts if you use RMI; while the initial client server contact is established through a registry operating on a standard port, the actual RMI communications is established using random ports, one for each link. -
How do you use .wsse policy file from Java Client?
I'd like to call a WSSE enabled web service from my Java client but setup my encryption/signing requirements with a .wsse policy file.
I know how to call a web service by programmatically setting up the security headers as described in:
http://e-docs.bea.com/workshop/docs81/doc/en/core/index.html
But how can I do the same thing by simply using a .wsse file?import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import java.net.*;
public class links extends java.applet.Applet {
Panel panel = new Panel();
public links(){
super();
add(panel);
Link link = new Link(this,"Answers for programmers;- ","http://forum.java.sun.com");
panel.add(link);
public void init(){
setVisible(true);
public class Link extends Label implements MouseListener {
Applet applet;
Color fcolor = Color.blue;
Color lcolor = Color.pink;
String text;
String word;
public Link(Applet ap, String s, String s1){
super(s);
this.applet = ap;
this.text = s;
this.word = s1;
addMouseListener(this);
setForeground(fcolor);
public void paint(Graphics g){
super.paint(g);
if (getForeground() == lcolor){
Dimension d = getSize();
g.fillRect(1,d.height-5,d.width,1);
public void update(Graphics g){paint(g);}
public void mouseClicked(MouseEvent e){
try{
URL url = new URL(word);
applet.getAppletContext().showDocument(url,"_self");
catch(MalformedURLException er){ }
public void mouseEntered(MouseEvent e){
setForeground(lcolor);
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
repaint();
public void mouseExited(MouseEvent e){
setForeground(fcolor);
setCursor(Cursor.getDefaultCursor());
repaint();
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public static void main (String[] args){
new links();
} -
How to upload file from client machine to database in server machine?
I am developing a web application. this application is suppose to take file from client machine and store that to database in the server side.
My jsp form is of multi part type. but I am confused about what to write in servlet.
Can any one help me ?
Edited by: chinmaya_mishra on Feb 16, 2009 2:55 AM
Edited by: chinmaya_mishra on Feb 16, 2009 2:58 AMhttp://www.google.com/search?q=jdbc+blob
Blob processing varies between databases; see also examples for whatever database you are using, e.g.
http://www.google.com/search?q=jdbc+blob+oracle
If you are storing text data instead of binary data, replace "blob" by "clob" in the searches. -
How to upload file from client to server
Can someone please help.
User needs to browse file on his desktop and upload file using browse button. This file should then be uploaded to the server. I am using javascript in the front end and servlet in the back.
Any help will be highly appreciated.
Thanks,
IndrasishJakarta Commons FileUpload is the standard way of doing the file uploading these days. You can find source, binaries and documentation at the Jakarta Site http://jakarta.apache.org/ . The Commons has a number of subprojects, so start with the Commons libraries, then find FileUpload.
Brian -
How to upload file from desktop or C drive and send as attachments
Hello Experts,
Please tell me
How to upload jpg or gif or drawing files from desktop or any drive and store into R/3 by the same time I have to send mail as a attachment.
I heard that FM
SO_NEW_DOCUMENT_ATT_SEND_API1 is only to send as a attachment what ever the data is present in the internal table only.
please help me on that.I m using this code its having attachment but I m not able to open the file. Please help me
I m using gui_upload to upload the file
PROGRAM ZTEST
no standard page heading line-size 255.
DATA: xfile TYPE string.
data : t_IW51 LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.
DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
DATA: DOC_CHNG LIKE SODOCCHGI1.
DATA: TAB_LINES LIKE SY-TABIX.
data : email type table of BAPIADSMTP.
PARAMETERS : file LIKE rlgrap-filename OBLIGATORY.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR file.
CLEAR file.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = file.
xfile = file.
START-OF-SELECTION.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = xfile
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = t_IW51.
Creation of the document to be sent
File Name
DOC_CHNG-OBJ_NAME = 'SENDFILE'.
Mail Subject
DOC_CHNG-OBJ_DESCR = 'Send External Mail'.
Mail Contents
OBJTXT = 'Minimum bid : $250000'.
APPEND OBJTXT.
OBJTXT = 'A representation of the pictures up for auction'.
APPEND OBJTXT.
OBJTXT = 'was included as attachment.'.
APPEND OBJTXT.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
Creation of the entry for the compressed document
CLEAR OBJPACK-TRANSF_BIN.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
Creation of the document attachment
(Assume that the data in OBJBIN is in BMP format)
*OBJBIN = ' \O/ '. APPEND OBJBIN.
*OBJBIN = ' | '. APPEND OBJBIN.
*OBJBIN = ' / \ '. APPEND OBJBIN.
OBJBIN[] = t_IW51[].
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
OBJHEAD = 'PICTURE.PDF'.
APPEND OBJHEAD.
OBJBIN[] = t_IW51[].
Creation of the entry for the compressed attachment
OBJPACK-TRANSF_BIN = 'X'.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 1.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'PDF'.
OBJPACK-OBJ_NAME = 'PICTURE'.
OBJPACK-OBJ_DESCR = 'Representation of object 138'.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.
Completing the recipient list
RECLIST-RECEIVER = 'email_id have to enter here'.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
RECLIST-RECEIVER = 'ENTEG01'.
RECLIST-REC_TYPE = 'P'.
APPEND RECLIST.
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
PUT_IN_OUTBOX = 'X'
commit_work = 'X'
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = OBJBIN
CONTENTS_TXT = OBJTXT
RECEIVERS = RECLIST
*EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
OPERATION_NO_AUTHORIZATION = 4
*OTHERS = 99.
CASE SY-SUBRC.
WHEN 0.
WRITE: / 'Result of the send process:'.
LOOP AT RECLIST.
WRITE: / RECLIST-RECEIVER(48), ':'.
IF RECLIST-RETRN_CODE = 0.
WRITE 'The document was sent'.
ELSE.
WRITE 'The document could not be sent'.
ENDIF.
ENDLOOP.
WHEN 1.
WRITE: / 'No authorization for sending to the specified number',
'of recipients'.
WHEN 2.
WRITE: / 'Document could not be sent to any recipient'.
WHEN 4.
WRITE: / 'No send authorization'.
WHEN OTHERS.
WRITE: / 'Error occurred while sending'.
ENDCASE. -
How to upload file from one machine (windows) to another (linux)through cre
How to upload a file from windows platform to linux platform.
on both platforms sun app server is running.
from creator is there any methode to open ftp port and uploadhttp://www.google.com/search?q=jdbc+blob
Blob processing varies between databases; see also examples for whatever database you are using, e.g.
http://www.google.com/search?q=jdbc+blob+oracle
If you are storing text data instead of binary data, replace "blob" by "clob" in the searches. -
Help: question on send XML file from java client to java server
Hi, I am now to Java, and now I am going to set up a simple network in the lab.
I have created a random array of data and transferred to XML file on my client. Now, I would like to send it to the server. I am wondering how I can put the XML file into my client, and do I need any parser to let the server show what random date it has received?
Anybody can give me any idea or some basic code? Thank you.
Now, I am referring the KnockKnock example in Java online tutorial. But, not clear how to deal with the XML File.
FengyuanThere are several ways you can achieve this: one could be that you transfer data over HTTP, using Servlets for instance. Have a Servlet listening on the Server with content type 'text/xml', POST the XML data to the server and have the Servlet to receive the data and re-compose the XML file. This can be achieved with different libraries:
1) JAXB --> this is good because is the JDK standard, also for web services
2) Castor (http://www.castor.org/) -
How to upload file from client to server in jsp
hello , In my application i have a requirement to upload picture and from it save to picture one with origional size and another with 100 * 100 size
Hi,
Give destination path is server address. for that u use
application.getRealPath("/");
It will return the server path.
-regards
Anna -
How to upload file from client machine to server machine?
i am developing one web application.I have one html file with browse option. client can browse any type of file. what ever file the client will browse it going to be stored in server machine. for storing the file want to use servlet. my html form is of multipart type.
can any one send me the servlet code? i am using tomcat 5.5 as web server.[http://commons.apache.org/fileupload]
Start reading 'User Guide' and 'Frequently Asked Questions'.
Good luck :) -
How to upload files from a form using pl/sql ?
Hi
Is it possible to upload the physical files outside the database (under UNIX server)using pl/sql? I already know how to store the files inside the database(wwwdoc_documents$) but I didn't find any documentation about storing the physical files outside the database.
I have in my form the following component:
<input type="file" name="upload">
and I want to let the user browse for the file on his/her disc that he want to use. What I want to do next is to save a copy of that file on our file-server, and then use it in my application. How do I do that in pl/sql?
Any help will be appreciated.
Sebas.Thanks for the suggestion. I like this approach as Java is more familiar to me than other languages.
Our DBA is out of touch today, so I could not grant the javauserpriv to my database user. I tried to run the script anyway in the chance that my user had the privs, and it seemed to have hung. I am now combing Oracle's site for more documentation so I can write some tests to see if I can get a basic Java object working. Under what heading would I find this?
ajt -
Different languages used while uploading file from java Application
Hi everybody,
i have a problem with multiple languages , let me clear you the question, i were developing a java application using spring ,hibernate frame works, so i got a problem while uploading a file with chinees language or other
it was saving with different format other than chiness in the database, can any one help me out ... i need the exact language when i upload the files,and when i get the data from DataBase which is in chinees language is '걨' going to be like as '???'
thank you very muchSanthosh_25 wrote:
using utf-8 characterSet, but its not showing properly
thank youOkay.. the problem with your browser settings.. (not sure)..
In firefox try to set character encoding...
go to View--->Character Encoding--->Unicode (UTF-8)..
In IE
go to View--->Encoding-->More-->Unicode (UTF-8)
set this and try.
Maybe you are looking for
-
Why can't I install IOS x Lion on Mac RAID?
I have a Mac Pro, OSX 10.6.8. Four hard drives 6TB in total. 3TB Start Up RAID striped, 3 TB backup Time Machine. I want to install Lion but get the message an error has occured. Any advice please?
-
Fixing Size of Column in Cross Tab
Plz tell me how to fix Size of column.in my case the data in column is not fixed so the output in PDF shows different size of Columns.I want want to fix them. plz help thanks in advance
-
How do you set the Language on the ipod 160 my ipod was preset when I took it out of the box I need it set to US English I order it from apple.com
-
CUCCX Historical reporting - how to separate views
Hi Guys, please dont you know how to make historical reporting reports accessible per team - I mean, defined login to HR tool can see only reports for defined teams, not for all of them. We gotta CUCCX 7.0(2) thanks Tomas
-
I cannot play videos because when I try to do so the following message occurs: "Proxy Detected...Your internet connection is currently using an HTTP proxy, content playback is not supported when a proxy is configured." How do I get rid of t