2012-12-11 3 views
0

지난 몇 주 동안 저는 Android 앱을 사용하여 PHP 서버에 게시 할 이미지를 얻었습니다. 나는 성공적으로 그것을 작동 시켰고 이미지에 '공유'를 칠 수 있었고 그것을 서버에 업로드 할 수있었습니다.앱 이미지 업로드 기능이 작동하지 않습니다.

나는 약 3 일 동안 몇 사람에게 보여줬고, 갑자기 오늘은 작동을 멈췄다. 이제 '공유'를 누르면 'ERROR website.com'이 표시되고 파일이 업로드되지 않습니다.

코드를 변경하지 않았습니다 (Eclipse에서 새 코드를 다시 업로드 한 적이 없으며 서버에서 PHP 파일을 편집하지 않은 것 같습니다).이 오류가 방금 튀어 나온 것처럼 보입니다. 아무데도. 그것은 단지 "ERROR website.com"이라고 말하기 때문에 설명 적이 지 않지만 웹 사이트가 문제라고 생각할 수 있습니다. 그래서 .php 파일을 검사했는데 여전히 의도대로 작동하고 웹 사이트가 손상되지 않았습니다.

아무도 원격으로 비슷한 것을 경험 했습니까? 아니면 이에 대한 답을 어디에서 찾을 수 있습니까?

안드로이드 코드 :

public class UploadImage extends Activity { 
InputStream inputStream; 

@Override 
public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    setContentView(R.layout.activity_starting_point); 

    Intent intent = getIntent(); 
    Bundle extras = intent.getExtras(); 
    String action = intent.getAction(); 

    // if this is from the share menu 
    if (Intent.ACTION_SEND.equals(action)) { 

     if (extras.containsKey(Intent.EXTRA_STREAM)) { 
      try { 

       // Get resource path from intent callee 
       Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM); 

       // Query gallery for camera picture via 
       // Android ContentResolver interface 
       ContentResolver cr = getContentResolver(); 
       InputStream is = cr.openInputStream(uri); 
       // Get binary bytes for encode 
       byte[] data = getBytesFromFile(is);   

       // base 64 encode for text transmission (HTTP) 
       int flags = 1; 
       byte[] encoded_data = Base64.encode(data, flags); 
       String image_str = new String(encoded_data); // convert to 
                   // string 

       ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 

       nameValuePairs.add(new BasicNameValuePair("image", 
         image_str)); 

       HttpClient httpclient = new DefaultHttpClient(); 
       HttpPost httppost = new HttpPost(
         "http://xxxx.php"); 
       httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
       HttpResponse response = httpclient.execute(httppost); 
       String the_string_response = convertResponseToString(response); 
       Toast.makeText(UploadImage.this, 
         "Response " + the_string_response, 
         Toast.LENGTH_LONG).show(); 
      } catch (Exception e) { 
       Toast.makeText(UploadImage.this, "ERROR " + e.getMessage(), 
         Toast.LENGTH_LONG).show(); 
       System.out.println("Error in http connection " 
         + e.toString()); 
      } 
     } 
    } 
} 

PHP 코드 :

<?php 
    if($base=$_REQUEST['image']){ 
    $binary=base64_decode($base); 
    header('Content-Type: bitmap; charset=utf-8'); 

    $destination = time() + rand(1, 1000) . ".jpg"; 
    $url_destination = "project_images/" . $destination; 

    $file = fopen($url_destination, 'wb'); 
    fwrite($file, $binary); 
    fclose($file); 
    echo 'Image upload complete.'; 
?> 
+0

PHP 파일은'ERROR website.com'을 반환 할 가능성이 가장 큽니다. 업로드 스크립트에 코드를 게시하는 것이 좋습니다 – Ronnie

+0

로니 (Ronnie)가 말했듯이 이것은 계속 진행하기에 충분한 정보가 아닙니다. 갑자기 실패 할 수있는 데는 여러 가지 이유가있을 수 있습니다. PHP 스크립트가 어떤 이유로 업로드를 거절하는 것 같지만 안드로이드 코드를 게시 할 가치가 있습니다. 그래서 살펴볼 수 있습니다. – mattgmg1990

+0

@Ronnie - 위의 게시물을 편집하여 코드를 표시했습니다. 또한 PHP 파일을 편집하고 내용을 모두 삭제했지만 PHP 파일에 나열되지 않은 'ERROR website'메시지가 표시됩니다. –

답변

1

내가 서버에 업로드 위치의 권한을 확인하거나 확인 임시 폴더를 확인하십시오 것 (예를 들어/tmp를)에는 업로드를받을 수있는 충분한 공간이 있습니다. 한 번 (다른 오류 메시지,하지만 같은 시나리오) 그 문제를 만났다.

+0

두 가지를 모두 확인했는데 슬프게도 이것이 문제가되지 않습니다. : / –

0

기기를 재부팅하면 모든 것이 올바르게 작동합니다. 왜 그런지 정확히 모르겠지만 그 기술은 당신에게 있습니다.

관련 문제