지난 몇 주 동안 저는 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.';
?>
PHP 파일은'ERROR website.com'을 반환 할 가능성이 가장 큽니다. 업로드 스크립트에 코드를 게시하는 것이 좋습니다 – Ronnie
로니 (Ronnie)가 말했듯이 이것은 계속 진행하기에 충분한 정보가 아닙니다. 갑자기 실패 할 수있는 데는 여러 가지 이유가있을 수 있습니다. PHP 스크립트가 어떤 이유로 업로드를 거절하는 것 같지만 안드로이드 코드를 게시 할 가치가 있습니다. 그래서 살펴볼 수 있습니다. – mattgmg1990
@Ronnie - 위의 게시물을 편집하여 코드를 표시했습니다. 또한 PHP 파일을 편집하고 내용을 모두 삭제했지만 PHP 파일에 나열되지 않은 'ERROR website'메시지가 표시됩니다. –