我正在使用 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 没有给出“成功”作为指示文件写入失败的消息。我将不胜感激。谢谢你。