简体   繁体   English

无法在实际服务器上写入图像文件

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

I'm working with android and try to create an app that able to upload several image to the server. 我正在使用android,并尝试创建一个能够将多个图片上传到服务器的应用。 I had tried to upload the image to my localhost using xampp, it works well. 我曾尝试使用xampp将图像上传到本地主机,效果很好。 But when I try to upload to my enterprise server I can't find my file, in the other word. 但是,换句话说,当我尝试上传到企业服务器时,找不到我的文件。 The file can't be written. 该文件无法写入。 I don't know what make it failed? 我不知道是什么使它失败了? This is my code 这是我的代码

Upload tp XAMPP 上传tp XAMPP

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

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

Upload to actual enterprise server 上传到实际的企业服务器

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

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

My code to upload to server 我的代码上传到服务器

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 code 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);

} }

I've contact my DBA and asked to give me permission to write the file, and it still doesn't work. 我已经联系我的DBA,并要求授予我写入文件的权限,但该文件仍然无法正常工作。 The error is json doesn't give "Success" as message that indicate the file failed to be written. 错误是json没有给出“成功”作为消息,指示文件写入失败。 I will appreciate any help. 我将不胜感激。 Thank you. 谢谢。

Does the file server allows write access permission? 文件服务器是否允许写访问权限? Sample of chmod, http://catcode.com/teachmod/ chmod示例, http://catcode.com/teachmod/

Is your enterprise server online? 您的企业服务器是否在线? The IP address looks private to me, 192.168.4.27. IP地址对我来说是私有的,192.168.4.27。

Dont use json use http post. 不要使用json使用http发布。

See below code 见下面的代码

    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);

Here img is your image in ByteArray format 这是您的ByteArray格式图像

我的DBA给我另一个文件路径后,问题解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM