2012-11-07 2 views
0

이제 몇 시간 동안이 문제로 어려움을 겪었습니다.http post 이후에 이미지를 서버에 저장 - android to ph

apachehttpclient jar 패키지를 사용하여 Android에서 PHP 서버로 멀티 파트 http 게시물 보내기. [정보]이 폴더에 이미지를 저장하려고 메신저를 PHP로 게시되면

그래서 나는 그것으로 작업 할 수 있습니다 내가 move_upload_file 상기와 또한 file_put_contents($newpath, $file);

모든 시도했다

<?php 

require("fpdf.php"); 

//Receive the data from android 
$name = $_POST['email']; 
$data = $_POST['data']; 

//Receive the file 
$file = $_FILES['image']; 

//$newpath = "/"; 
//file_put_contents($newpath, $file); 

if(move_uploaded_file($file, $newpath)) { 

echo json_encode(
     array(
      'result'=>$data, 
      'msg'=>'Report added successfully.' 
      ) 
     ); 
}else { 
//something else 
}; 

?> 

도움이 크게 감사합니다.

+0

이 목업 코드 또는 사용중인 코드가 맞습니까? 후자의 경우 하단의 조건문에 닫는 괄호를 주석 처리했습니다. 그러나 문제가되는 것은 너무 사소한 것처럼 보이므로, 내가 잘못한 것을보고 있으면 무시해주십시오. – Beardy

+0

사과. 네, 그냥 코드를 조롱하는 것입니다. 나는 이것을 수정 한 – EHarpham

답변

1

이것은 ios 응용 프로그램에서 서버로 사진을 업로드 할 때 사용하는 PHP 스크립트입니다.

<?php 
$uploadDir = './images/';  //Uploading to directory specified 
$file = basename($_FILES['userfile']['name']); 
$uploadFile = $file; 
$randomNumber = rand(0, 99999999999); 
$newName = $uploadDir . $randomNumber . $uploadFile; 


if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { 
    echo "Temp file uploaded. \r\n"; 
} else { 
    echo "Temp file not uploaded. \r\n"; 
} 

if ($_FILES['userfile']['size']> 100000000) { 
    exit("Your file is too large."); 
} 

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $newName)) { 
    $maxsize = ini_get('upload_max_filesize'); 
    echo "http://www.mydomain.com/images/{$file}" . "\r\n" . $_FILES['userfile']['size'] . "\r\n" . $_FILES['userfile']['type'] ; 
    echo $randomNumber; 
} 
?> 
+0

고맙습니다. – EHarpham

관련 문제