2015-06-22 84 views
0

我正在開發一個android應用程序,它需要將使用相機拍攝的圖像上傳到服務器。我用這個教程和導入項目 from this link, refer this for android code圖片從android應用程序上傳到服務器不起作用

我的PHP文件,它表明圖像的成功,並返回我的網址,但在服務器上找不到圖像。我無法解決這個問題。

我的PHP文件中的代碼是:

<?php 

// Path to move uploaded files 
$target_path = "Upload_image_ANDROID/"; 

// array for final json respone 
$response = array(); 

// getting server ip address 
$server_ip = '216.86.147.200'; 

// final file url that is being uploaded 
$file_upload_url = 'http://' . $server_ip . '/' . 'sss_api' . '/' . $target_path; 


if (isset($_FILES['image']['name'])) { 
    $target_path = $target_path . basename($_FILES['image']['name']); 

    // reading other post parameters 
    // $email = isset($_POST['email']) ? $_POST['email'] : ''; 
    //$website = isset($_POST['website']) ? $_POST['website'] : ''; 

    $response['file_name'] = basename($_FILES['image']['name']); 
    //$response['email'] = $email; 
    //$response['website'] = $website; 

    try { 
     // Throws exception incase file is not being moved 
     if (!move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) { 
      // make error flag true 
      $response['error'] = true; 
      $response['message'] = 'Could not move the file!'; 
     } 

     // File successfully uploaded 
     $response['message'] = 'File uploaded successfully!'; 
     $response['error'] = false; 
     $response['file_path'] = $file_upload_url . basename($_FILES['image']['name']); 
    } catch (Exception $e) { 
     // Exception occurred. Make error flag true 
     $response['error'] = true; 
     $response['message'] = $e->getMessage(); 
    } 
} else { 
    // File parameter is missing 
    $response['error'] = true; 
    $response['message'] = 'Not received any file!F'; 
} 

// Echo final json response to client 
echo json_encode($response); 
?> 
+0

更多信息,你可以添加一些回聲報表,看看您的變量的值是 – Jens

回答

0

如果按照教程結束,你的Android應用程序正在您的設備上如預期,這個問題更在服務器端,由於許可 ,您的服務器不允許您保存該文件。

嘗試將位置設置到一個文件夾在您的應用程序將具有寫權限或更改htaccess的你可以得到http://httpd.apache.org/docs/2.2/howto/htaccess.html

相關問題