Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 文件未正确上载_Php_Android_File Upload - Fatal编程技术网

Php 文件未正确上载

Php 文件未正确上载,php,android,file-upload,Php,Android,File Upload,在我的android应用程序中,我必须将文件上传到服务器并在服务器端读取文件。正在上载文件,但有时会发生这种情况,在文件夹中(文件所在的服务器上),如果以前上载的文件存在,则当前上载的文件将使用以前的文件数据生成。e、 g.假设我将名为A的文件上载到数据为'1、2和3'的服务器,则服务器端文件夹下会有文件A.txt,数据为'A,如果现在我将名为B的文件上载到数据为'A的服务器,B和C'则文件夹下的文件B.txt将在那里,但之前的文件数据为A.txt。所以在B.txt中,数据是'1、2和3'。下面

在我的android应用程序中,我必须将文件上传到服务器并在服务器端读取文件。正在上载文件,但有时会发生这种情况,在文件夹中(文件所在的服务器上),如果以前上载的文件存在,则当前上载的文件将使用以前的文件数据生成。e、 g.假设我将名为A的文件上载到数据为'1、2和3'的服务器,则服务器端文件夹下会有文件
A.txt
,数据为'A,如果现在我将名为B的文件上载到数据为'A的服务器,B和C'则文件夹下的文件
B.txt
将在那里,但之前的文件数据为
A.txt
。所以在
B.txt
中,数据是'1、2和3'。下面是我的代码。问题是什么

安卓端 PHP端
为什么在$objFile=&$_FILES[“file”];处使用“&”@阿比娅:可能是我的语法错误。我把它取下来试了试,但得到了同样的问题
public void uploadUserFriendId(String user_id, String filePath, String fileName)
    {
        String server_url = "http://addressofserver/folder/myfile.php";
        InputStream inputStream;
        try
        {
            inputStream = new FileInputStream(new File(filePath));
            byte[] data;
            try
            {
                data = IOUtils.toByteArray(inputStream);

                HttpClient httpClient = new DefaultHttpClient();

                httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT,
                        System.getProperty("http.agent"));



                HttpPost httpPost = new HttpPost(server_url);
                InputStreamBody inputStreamBody = new InputStreamBody(new ByteArrayInputStream(data), fileName);
                MultipartEntity multipartEntity = new MultipartEntity();
                multipartEntity.addPart("file", inputStreamBody);
                multipartEntity.addPart("user_id", new StringBody(user_id));

                httpPost.setEntity(multipartEntity);
                HttpResponse httpResponse = httpClient.execute(httpPost);



                // Handle response back from script.
                if(httpResponse != null) {
                    //Toast.makeText(getBaseContext(),  "Upload Completed. ", 2000).show();

                } else { // Error, no response.
                    //Toast.makeText(getBaseContext(),  "Server Error. ", 2000).show();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        }
    }
<?php

 error_reporting(~0); 
 ini_set('display_errors', 1);

    mysql_connect("localhost", "root", "Admin@123") or die(mysql_error()) ; 
    mysql_select_db("retail_menu") or die(mysql_error()) ; 


    $today =date("YmdHis");
    $pic=$today.".txt";

    if (isset($_POST["user_id"]) && !empty($_POST["user_id"]))
    {
        $user_id=$_POST['user_id']; 
    }
    else
    {  
        $user_id="null"; 
    }

    $objFile = & $_FILES["file"];

    // here file is created under folder named upload at server side
    if( move_uploaded_file( $objFile["tmp_name"], "upload/".$user_id.".txt" ) )
    {

        $file = fopen("upload/".$user_id.".txt" ,"r");

        while(! feof($file))
        {
            $friend_id = fgets($file, 8192);
            if($friend_id!= null)
            {
                $query = "INSERT IGNORE INTO table_name (user_id, friend_id) values('$user_id', '$friend_id')";
                var_dump($query);
                mysql_query($query); 
            }
        }
            fclose($file);
    } 

    else 
    {
        print "There was an error uploading the file, please try again!";
    }


?>