둘다 같은원리라고생각해서

음악파일 리스트뷰로뿌려주고 절대경로얻어서 이미지파일같이 보내주려고했는데 자꾸 예외처리뜨네요 ㅠ


public static void DoFileUpload(String apiUrl, String absolutePath) {

HttpFileUpload(apiUrl, "", absolutePath);

}


public static void HttpFileUpload(String urlString, String params, String fileName) {

try {

// sendID();

String lineEnd = "\r\n";

String twoHyphens = "--";

String boundary = "*****";

FileInputStream mFileInputStream = new FileInputStream(fileName);

urlString += "?id=";

urlString += main.usr.getUserId();

urlString += "&path=" + fileName;

Log.d("Test", urlString);

URL connectUrl = new URL("urlString);

Log.d("Test", "mFileInputStream  is " + mFileInputStream);


// open connection

HttpURLConnection conn = (HttpURLConnection) connectUrl

.openConnection();

conn.setDoInput(true);

conn.setDoOutput(true);

conn.setUseCaches(false);

conn.setRequestMethod("POST");

conn.setRequestProperty("Connection", "Keep-Alive");

conn.setRequestProperty("Content-Type",

"multipart/form-data;boundary=" + boundary);


// write data

DataOutputStream dos = new DataOutputStream(conn.getOutputStream());

dos.writeBytes(twoHyphens + boundary + lineEnd);

dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\""

+ fileName + "\"" + lineEnd);

dos.writeBytes(lineEnd);


int bytesAvailable = mFileInputStream.available();

int maxBufferSize = 1*1024*1024;

int bufferSize = Math.min(bytesAvailable, maxBufferSize);


byte[] buffer = new byte[bufferSize];

int bytesRead = mFileInputStream.read(buffer, 0, bufferSize);


Log.d("Test", "image byte is " + bytesRead);


// read image

while (bytesRead > 0) {

dos.write(buffer, 0, bufferSize);

bytesAvailable = mFileInputStream.available();

bufferSize = Math.min(bytesAvailable, maxBufferSize);

bytesRead = mFileInputStream.read(buffer, 0, bufferSize);

}


dos.writeBytes(lineEnd);

dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);


// close streams

Log.e("Test", "File is written");

mFileInputStream.close();

dos.flush(); // finish upload...


// get response

int ch;

InputStream is = conn.getInputStream();

StringBuffer b = new StringBuffer();

while ((ch = is.read()) != -1) {

b.append((char) ch);

}

String s = b.toString();

Log.e("Test", "result = " + s);

// mEdityEntry.setText(s);

dos.close();


} catch (Exception e) {

Log.d("Test", "exception " + e.getMessage());

// TODO: handle exception

}

}


}



<?php

$usrid = $_REQUEST['id'];

$uploaddir = $usrid.'/';

 $path = $_REQUEST['path'];


    $arr_filename = explode('.', $_FILES['uploadedfile']['name']);


    if ($arr_filename[1] == "php" || $arr_filename[1] == "php3" || $arr_filename[1] == "php4" || $arr_filename[1] == "php5" || $arr_filename[1] == "kr" || $arr_filename[1] == "html" || $arr_filename[1] == "htm" || $arr_filename[1] == "asp" || $arr_filename[1] == "jsp" || $arr_filename[1] == "cgi" || $arr_filename[1] == "inc"  || $arr_filename[1] == "pl") {

echo "OHMYGOD";

Exit;

    }


    $uploadfile = $uploaddir.basename($_FILES['uploadedfile']['name']);

    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$uploadfile)) {

        echo $path;

    } else {

        echo $usrid;

    }

$file_type = $_FILES['uploadedfile']['type'];

$tmp_type = $_FILES['uploadedfile']['tmp_name'];

$file_size = $_FILES['uploadedfile']['size'];

$time = time();

$c_filename = $usrid.$time."."."dalpha";

$ori_filename = str_replace(" ","_", $arr_filename[0]);



php파일입니다