2013-08-28 1 views
0

저는 Android에서 작업 중이며 여러 이미지를 서버에 업로드 할 수있는 앱을 만들려고합니다. xampp을 사용하여 localhost에 이미지를 업로드하려고 시도했지만 제대로 작동합니다. 그러나 엔터 프라이즈 서버에 업로드하려고하면 파일을 찾을 수 없습니다. 파일을 쓸 수 없습니다. 무엇이 실패했는지 모르겠습니다. 이실제 서버에 이미지 파일을 쓸 수 없습니다.

업로드 TP XAMPP

연결 문자열 private static final String url_photo = "http://192.168.7.110/blabla/base.php";

경로 static final String path = "C:\\xampp\\htdocs\\psn_asset_oracle\\Images\\";

업로드 실제 기업의 서버에 내 코드입니다

연결 문자열 private static final String url_photo = "http://192.168.4.27/oracle/logam/am/data_images/android_image/base.php";

경로 static final String path = "http://192.168.4.27/oracle/logam/am/data_images/android_image/";

내 코드를 서버에 업로드하는

params_p.add(new BasicNameValuePair("image_name_1", 
         image_name_1)); 
       params_p.add(new BasicNameValuePair("image_name_2", 
         image_name_2)); 
       params_p.add(new BasicNameValuePair("image_name_3", 
         image_name_3)); 
       params_p.add(new BasicNameValuePair("image_name_4", 
         image_name_4)); 
json_photo = jsonParser.makeHttpRequest(url_photo, "POST", params_p); 
ArrayList<NameValuePair> params_p = new ArrayList<NameValuePair>(); 

PHP 코드

if(isset($_POST["image_name_1"]) && isset($_POST["image_name_2"]) && isset($_POST["image_name_3"]) && isset($_POST["image_name_4"]) 
&& isset($_POST["image_1"]) && isset($_POST["image_2"]) && isset($_POST["image_3"]) && isset($_POST["image_4"])) 
{ 
$image_name_1 = $_POST["image_name_1"]; 
$image_name_2 = $_POST["image_name_2"]; 
$image_name_3 = $_POST["image_name_3"]; 
$image_name_4 = $_POST["image_name_4"]; 
$image_1 = $_POST["image_1"]; 
$image_2 = $_POST["image_2"]; 
$image_3 = $_POST["image_3"]; 
$image_4 = $_POST["image_4"]; 

/*---------base64 decoding utf-8 string-----------*/ 
$binary_1=base64_decode($image_1); 
$binary_2=base64_decode($image_2); 
$binary_3=base64_decode($image_3); 
$binary_4=base64_decode($image_4); 

/*-----------set binary, utf-8 bytes----------*/ 
header('Content-Type: bitmap; charset=utf-8'); 
/*---------------open specified directory and put image on it------------------*/ 
$file_1 = fopen($image_name_1, 'wb'); 
$file_2 = fopen($image_name_2, 'wb'); 
$file_3 = fopen($image_name_3, 'wb'); 
$file_4 = fopen($image_name_4, 'wb'); 

/*---------------------assign image to file system-----------------------------*/ 
fwrite($file_1, $binary_1); 
fclose($file_1); 
fwrite($file_2, $binary_2); 
fclose($file_2); 
fwrite($file_3, $binary_3); 
fclose($file_3); 
fwrite($file_4, $binary_4); 
fclose($file_4); 

$response["message"] = "Success"; 
echo json_encode($response); 

}

나는 아직도 내 DBA에게 연락했고 나에게 파일을 쓸 수있는 권한을 부여하도록 요청하고, 작동하지 않습니다. 오류는 json이 파일을 쓰지 못했음을 나타내는 "Success"메시지를 표시하지 않습니다. 나는 어떤 도움을 주셔서 감사합니다. 고맙습니다.

답변

0

파일 서버가 쓰기 권한을 허용합니까? chmod 예제, http://catcode.com/teachmod/

엔터프라이즈 서버는 온라인 상태입니까? IP 주소는 192.168.4.27에 비공개로 보입니다.

+0

예. 내 dba가 변경 사실을 알려줍니다. 물론 개인적으로 보이지만 그 ip로부터 질의를 성공적으로 삽입합니다. –

0

json은 http 포스트를 사용하지 마십시오.

여기
HttpClient client = new DefaultHttpClient(); 
    String postURL = "your url"; 
    HttpPost post = new HttpPost(postURL); 

    try { 
     MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 

     ByteArrayBody bab = new ByteArrayBody(img, "image.jpg"); 
     reqEntity.addPart("image", bab); 
     post.setEntity(reqEntity); 
     HttpResponse response = client.execute(post); 

IMG 나에게 또 다른 파일 경로를 줄이 ByteArray 형식

+0

멀티 파트로 변경해야하는 이유를 설명 할 수 있습니까? xampp을 사용하여 로컬 서버에서이 작업을 수행 할 수 있기 때문입니다. –

0

내 DBA 후 해결 문제에 이미지 코드 아래를 참조하십시오.

관련 문제