簡體   English   中英

無法在實際服務器上寫入圖像文件

[英]Can't write image file on actual server

我正在使用android,並嘗試創建一個能夠將多個圖片上傳到服務器的應用。 我曾嘗試使用xampp將圖像上傳到本地主機,效果很好。 但是,換句話說,當我嘗試上傳到企業服務器時,找不到我的文件。 該文件無法寫入。 我不知道是什么使它失敗了? 這是我的代碼

上傳tp XAMPP

連接字符串private static final String url_photo = "http://192.168.7.110/blabla/base.php";

路徑static final String path = "C:\\\\xampp\\\\htdocs\\\\psn_asset_oracle\\\\Images\\\\";

上傳到實際的企業服務器

連接字符串private static final String url_photo = "http://192.168.4.27/oracle/logam/am/data_images/android_image/base.php";

路徑static final String path = "http://192.168.4.27/oracle/logam/am/data_images/android_image/";

我的代碼上傳到服務器

params_p.add(new BasicNameValuePair("image_name_1",
                        image_name_1));
                params_p.add(new BasicNameValuePair("image_name_2",
                        image_name_2));
                params_p.add(new BasicNameValuePair("image_name_3",
                        image_name_3));
                params_p.add(new BasicNameValuePair("image_name_4",
                        image_name_4));
json_photo = jsonParser.makeHttpRequest(url_photo, "POST", params_p);
ArrayList<NameValuePair> params_p = new ArrayList<NameValuePair>();

PHP代碼

if(isset($_POST["image_name_1"]) && isset($_POST["image_name_2"]) && isset($_POST["image_name_3"]) && isset($_POST["image_name_4"]) 
&& isset($_POST["image_1"]) && isset($_POST["image_2"]) && isset($_POST["image_3"]) && isset($_POST["image_4"]))
{
$image_name_1 = $_POST["image_name_1"];
$image_name_2 = $_POST["image_name_2"];
$image_name_3 = $_POST["image_name_3"];
$image_name_4 = $_POST["image_name_4"];
$image_1 = $_POST["image_1"];
$image_2 = $_POST["image_2"];
$image_3 = $_POST["image_3"];
$image_4 = $_POST["image_4"];

/*---------base64 decoding utf-8 string-----------*/
$binary_1=base64_decode($image_1);
$binary_2=base64_decode($image_2);
$binary_3=base64_decode($image_3);
$binary_4=base64_decode($image_4);

/*-----------set binary, utf-8 bytes----------*/
header('Content-Type: bitmap; charset=utf-8');
/*---------------open specified directory and put image on it------------------*/
$file_1 = fopen($image_name_1, 'wb');
$file_2 = fopen($image_name_2, 'wb');
$file_3 = fopen($image_name_3, 'wb');
$file_4 = fopen($image_name_4, 'wb');

/*---------------------assign image to file system-----------------------------*/
fwrite($file_1, $binary_1);
fclose($file_1);
fwrite($file_2, $binary_2);
fclose($file_2);
fwrite($file_3, $binary_3);
fclose($file_3);
fwrite($file_4, $binary_4);
fclose($file_4);

$response["message"] = "Success";
echo json_encode($response);

}

我已經聯系我的DBA,並要求授予我寫入文件的權限,但該文件仍然無法正常工作。 錯誤是json沒有給出“成功”作為消息,指示文件寫入失敗。 我將不勝感激。 謝謝。

文件服務器是否允許寫訪問權限? chmod示例, http://catcode.com/teachmod/

您的企業服務器是否在線? IP地址對我來說是私有的,192.168.4.27。

不要使用json使用http發布。

見下面的代碼

    HttpClient client = new DefaultHttpClient();
    String postURL = "your url";
    HttpPost post = new HttpPost(postURL);

    try {
        MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

        ByteArrayBody bab = new ByteArrayBody(img, "image.jpg");
        reqEntity.addPart("image", bab); 
        post.setEntity(reqEntity);
        HttpResponse response = client.execute(post);

這是您的ByteArray格式圖像

我的DBA給我另一個文件路徑后,問題解決了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM