Android 장치 용 PHP를 사용하는 웹 서비스를 처음 사용합니다. 여러 이미지 업로드 개념을 작업해야합니다. 제안 해주세요. 단일 업로드 개념을 구현했습니다. 단일 파일 업로드 코드는 아래와 같습니다.
$data = $_REQUEST;
if($data["prop_images"]){
$filename = md5(time()).'.jpg';
$base=$data["prop_images"];
$binary = base64_decode($base);
$pathtoupload = JPATH_ADMINISTRATOR . '/components/com_clinchproperties/galupload/';
//header('Content-Type: bitmap; charset=utf-8'); // binary, utf-8 bytes
$actual_image_name = time().".jpg";
$image = $filename;
$file = fopen($pathtoupload.$filename, 'wb');
fwrite($file, $binary);
fclose($file);
}
n 개의 이미지를 동시에 업로드하려면 코드가 필요합니다. 아무도 나를 도울 수 있습니까? 미리 감사드립니다.
파일 배열을 전달해야합니다. 주석에서 언급했듯이 파일 데이터를 base64 형식으로 보내고 있습니다 PHP
..
PHP
$data = $_REQUEST;
if($data["prop_images"]){
foreach($data["prop_images"] as $img){ //array of images. So loop for every images
$filename = md5(time()).'.jpg';
$base=$img;
$binary = base64_decode($base);
$pathtoupload = JPATH_ADMINISTRATOR . '/components/com_clinchproperties/galupload/';
$actual_image_name = time().".jpg";
$image = $filename;
$file = fopen($pathtoupload.$filename, 'wb');
fwrite($file, $binary);
fclose($file);
}
}
Android 코드에서 []
POST 요청을하는 동안 매개 변수 이름 을 추가해야합니다 . 그 매개 변수는 prop_images[]
위에 주어진 예에 따라야합니다 .
저는 Android 개발자는 아니지만 Android 개발자로부터 코드를 게시 할 수 있습니다.
기계적 인조 인간
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost("http://webserver.com/path/to/webservice.php");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
for (int i = 0; i < number_of_images; i++) {
//convert your images to base64 and store in base64ImageData.
reqEntity.addPart("prop_images[]", base64ImageData); //adding parameter
}
//execute request.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다