android — загрузка файлов и строк на php сервер

Я хочу загрузить файлы и строки в HTML-форму на сервере PHP. Я загрузил файлы с кодом ниже, но я не знаю, как загрузить строку. Как мне изменить этот код для загрузки строк в текстовые поля формы?
Моя HTML-форма:

    <form name="form" id="gallery" method="post" enctype="multipart/form-data" action="send_1.php">
<div id="contain" >
<div class='file_browse_wrapper' id="file1">
<input type="file" size="32" name="file1" value=""  />
<input type="file" size="32" name="file2" value=""  />
<input type="text" size="32" name="phonenumber" value="1234" />
<input type="text" size="32" name="uploadmessage" value="some text" />
</div>
</div><br>
<input type="submit" name="add" id="add" value="click me" /><!--end add-->
</form><!--end form-->

Мне удалось загрузить файлы с этим кодом:

 public int uploadFiles(int pictureNumber, String strToUpload1, String strToUpload2) {
String uploadServerUri;
String uploadFilePath = Environment.getExternalStorageDirectory().toString() + "/Pictures/MyCameraApp/";
final int timeStamp;
int serverResponseCode = 0;
HttpURLConnection conn = null;
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1 * 1024 * 1024;
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
DataOutputStream doc = null;
FileInputStream fileInputStream = null;
String[] paths = new String[2];

for(int i=0; i<2; i++) {
paths[i] = uploadFilePath + timeStamp +"-" + Integer.toString( pictureNumber + i ) + ".jpg" ;
}
try {
URL url = new URL(uploadServerUri);
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true); // Allow Inputs
conn.setDoOutput(true); // Allow Outputs
conn.setUseCaches(false); // Don't use a Cached Copy
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("ENCTYPE", "multipart/form-data");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
for(int i=0; i<2; i++)
conn.setRequestProperty("uploadedfile" + Integer.toString(i), paths[i]);
for(int i=0; i<2; i++) {
File sourceFile = new File(paths[i]);
fileInputStream = new FileInputStream(sourceFile);
Log.d(TAG, ".....start uploading file"+ Integer.toString(i));
doc = new DataOutputStream(conn.getOutputStream());
doc.writeBytes(twoHyphens + boundary + lineEnd);
doc.writeBytes("Content-Disposition: form-data; name=\"uploadedfile" + (i + 1) + "\"" + ";filename=\""+ paths[i] + "\"" + lineEnd);
doc.writeBytes(lineEnd);
// create a buffer of  maximum size
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
// read file and write it into form...
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0) {
doc.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
// send multipart form data necesssary after file data...
doc.writeBytes(lineEnd);
doc.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
Log.d(TAG, ".....upload file "+Integer.toString(i)+" completed");
fileInputStream.close();
doc.flush();
}//end of for
// Responses from the server (code and message)
serverResponseCode = conn.getResponseCode();
String serverResponseMessage = conn.getResponseMessage();
Log.d(TAG, "HTTP Response is : "+ serverResponseMessage + ": " + serverResponseCode);
if(serverResponseCode == 200)
Log.d(TAG, "upload completed");
doc.close();
}//end of first try
catch (MalformedURLException e) {
Log.e(TAG, e.getMessage().toString()+"..."+"MalformedURLException Exception : check script url.");
}
catch (Exception e) {
Log.e(TAG, e.getMessage().toString());
}
return serverResponseCode;

}

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]