Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.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 android视频上传到服务器_Php_Android - Fatal编程技术网

Php android视频上传到服务器

Php android视频上传到服务器,php,android,Php,Android,嘿,伙计们,试图从android设备向服务器发送视频,我在网上发现了一些代码,似乎对其他人来说是正确的,但出于某种原因,它对我不起作用,我正在使用一个免费的000webserver,如果这与此有关,这里是我的代码 java代码 TextView tv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); se

嘿,伙计们,试图从android设备向服务器发送视频,我在网上发现了一些代码,似乎对其他人来说是正确的,但出于某种原因,它对我不起作用,我正在使用一个免费的000webserver,如果这与此有关,这里是我的代码

java代码

TextView tv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newtest);
        tv = (TextView) findViewById(R.id.tv);
        new videoUpload().execute("");
    }



private class videoUpload extends AsyncTask<String, String, String> {
    @Override
    protected String doInBackground(String... urls) {

        HttpURLConnection conn = null;
        DataOutputStream dos = null;
        DataInputStream inStream = null;


        // Is this the place are you doing something wrong.

        String lineEnd = "\r\n";
        String twoHyphens = "--";
        String boundary =  "*****";


        int bytesRead, bytesAvailable, bufferSize;

        byte[] buffer;

        int maxBufferSize = 1*1024*1024;

        String urlString = "http://www.gogodis.comxa.com/vid.php";



        try
        {


            Log.e("MediaPlayer", "Inside second Method");

            FileInputStream fileInputStream = new FileInputStream(new File(Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_MOVIES), "ReallyChat/vids/RC_go.3gp") );



            URL url = new URL(urlString);

            conn = (HttpURLConnection) url.openConnection();

            conn.setDoInput(true);

            // Allow Outputs
            conn.setDoOutput(true);

            // Don't use a cached copy.
            conn.setUseCaches(false);

            // Use a post method.
            conn.setRequestMethod("POST");

            conn.setRequestProperty("Connection", "Keep-Alive");

            conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);



            dos = new DataOutputStream( conn.getOutputStream() );

            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + exsistingFileName +"\"" + lineEnd);
            dos.writeBytes(lineEnd);

            Log.e("MediaPlayer","Headers are written");



            bytesAvailable = fileInputStream.available();
            bufferSize = Math.min(bytesAvailable, maxBufferSize);
            buffer = new byte[bufferSize];



            bytesRead = fileInputStream.read(buffer, 0, bufferSize);

            while (bytesRead > 0)
            {
                dos.write(buffer, 0, bufferSize);
                bytesAvailable = fileInputStream.available();
                bufferSize = Math.min(bytesAvailable, maxBufferSize);
                bytesRead = fileInputStream.read(buffer, 0, bufferSize);
            }



            dos.writeBytes(lineEnd);

            dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

            BufferedReader in = new BufferedReader(
                    new InputStreamReader(
                            conn.getInputStream()));
            String inputLine;

            while ((inputLine = in.readLine()) != null)
                tv.append(inputLine);




            // close streams
            Log.e("MediaPlayer","File is written");
            fileInputStream.close();
            dos.flush();
            dos.close();


        }
        catch (MalformedURLException ex)
        {
            Log.e("MediaPlayer", "error: " + ex.getMessage(), ex);
        }

        catch (IOException ioe)
        {
            Log.e("MediaPlayer", "error: " + ioe.getMessage(), ioe);
        }

        try {
            inStream = new DataInputStream ( conn.getInputStream() );
            String str;

            while (( str = inStream.readLine()) != null)
            {
                Log.e("MediaPlayer","Server Response"+str);
            }
            /*while((str = inStream.readLine()) !=null ){

            }*/
            inStream.close();

        }
        catch (IOException ioex){
            Log.e("MediaPlayer", "error: " + ioex.getMessage(), ioex);
        }
        return null;
    }

    @Override
    protected void onPostExecute(String result) {

    }
}
php


顺便说一下,这种情况一直在发生,到目前为止,我无法上传任何内容。

…使用像LoopJ或OkHttp这样的http客户端库,他们有演示示例。…使用像LoopJ或OkHttp这样的http客户端库,他们有演示示例。
02-29 11:15:16.172 31225-3829/com.reallyChat E/MediaPlayer: error: sendto failed: EPIPE (Broken pipe)
java.net.SocketException: sendto failed: EPIPE (Broken pipe)
    at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:506)
    at libcore.io.IoBridge.sendto(IoBridge.java:475)
    at java.net.PlainSocketImpl.write(PlainSocketImpl.java:507)
    at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)
    at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:269)
    at java.io.ByteArrayOutputStream.writeTo(ByteArrayOutputStream.java:231)
    at libcore.net.http.RetryableOutputStream.writeToSocket(RetryableOutputStream.java:70)
    at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:814)
    at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
    at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
    at com.really_chat.newtest$statusUpdateTask.doInBackground(newtest.java:132)
    at com.really_chat.newtest$statusUpdateTask.doInBackground(newtest.java:40)
    at android.os.AsyncTask$2.call(AsyncTask.java:287)
    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
    at java.lang.Thread.run(Thread.java:856)
 Caused by: libcore.io.ErrnoException: sendto failed: EPIPE (Broken pipe)
    at libcore.io.Posix.sendtoBytes(Native Method)
    at libcore.io.Posix.sendto(Posix.java:151)
    at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)
    at libcore.io.IoBridge.sendto(IoBridge.java:473)
    at java.net.PlainSocketImpl.write(PlainSocketImpl.java:507) 
    at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46) 
    at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:269) 
    at java.io.ByteArrayOutputStream.writeTo(ByteArrayOutputStream.java:231) 
    at libcore.net.http.RetryableOutputStream.writeToSocket(RetryableOutputStream.java:70) 
    at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:814) 
    at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283) 
    at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177) 
    at com.really_chat.newtest$statusUpdateTask.doInBackground(newtest.java:132) 
    at com.really_chat.newtest$statusUpdateTask.doInBackground(newtest.java:40) 
    at android.os.AsyncTask$2.call(AsyncTask.java:287) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
    at java.lang.Thread.run(Thread.java:856) 
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], "img/".$_FILES["uploadedfile"]["name"]);