title: Android: App does not upload video in apache server
body: <p>I have an Android app where the user can shoot a video, then click a button to upload the video to a folder named "Uploads" located in localhost. When I run the app on the emulator everything works the way it is supposed to. But when I run it on an actual android device the video is not uploaded to my "Uploads" folder and I get a "Could not move the file!" response.</p>
  
  <p>Here is the PHP script I use to move the file :</p>
  
  <pre><code>&lt;?php
  
  // Path to move uploaded files
  $target_path = "Uploads/";
  
  // array for final json respone
  $response = array();
  
  // getting server ip address
  $server_ip = gethostbyname(gethostname());
  
  // final file url that is being uploaded
  $file_upload_url = 'http://' . $server_ip . '/' . 'UploadedVideos' . '/' . $target_path;
  chmod($_SERVER['DOCUMENT_ROOT'] . '/' . 'UploadedVideos' . '/' . 'Uploads', 0777);
  
  if (isset($_FILES['video']['name'])) {
      $target_path = $target_path . basename($_FILES['video']['name']
  
      try {
   // Throws exception incase file is not being moved
  
    if (!move_uploaded_file($_FILES['video']['tmp_name'], $target_path)) {
     // make error flag true
     $response['error'] = true;
     $response['message'] = 'Could not move the file!';
    } else {
  
      // File successfully uploaded
      $response['message'] = 'File uploaded successfully!';
      $response['error'] = false;
  
      $response['file_path'] = $file_upload_url . basename($_FILES['video']['name']);
    }
   } catch (Exception $e) {
     // Exception occurred. Make error flag true
     $response['error'] = true;
     $response['message'] = $e-&gt;getMessage();
   }
  } else {
   // File parameter is missing
   $response['error'] = true;
   $response['message'] = 'Not received any file!F';
  }
  
  // Echo final json response to client
  echo json_encode($response);
  ?&gt;
  </code></pre>
  
  <p>I think this has to do with the "Uploads" folder write permissions on Windows 8.1, so I am asking you : How do I give write permission to a folder in order to be accessible from an Android Device? </p>
  
  <p>Edit: UploadActivity.java</p>
  
  <pre><code>public class UploadActivity extends Activity {
      // LogCat tag
      private static final String TAG = MainActivity.class.getSimpleName();
  
      private ProgressBar progressBar;
      private String filePath = null;
      public String serverPath;
      private TextView txtPercentage;
      SQLiteDatabase db;
      private VideoView vidPreview;
      private Button btnUpload;
      long totalSize = 0;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_upload);
          txtPercentage = (TextView) findViewById(R.id.txtPercentage);
          btnUpload = (Button) findViewById(R.id.btnUpload);
          progressBar = (ProgressBar) findViewById(R.id.progressBar);
  
          vidPreview = (VideoView) findViewById(R.id.videoPreview);
          // Receiving the data from previous activity
          Intent i = getIntent();
  
          // image or video path that is captured in previous activity
          filePath = i.getStringExtra("filePath");
          serverPath = i.getStringExtra("serverPath");
  
  
          if (filePath != null) {
              // Displaying video on the screen
              previewMedia();
          } else {
              Toast.makeText(getApplicationContext(),
                      "Sorry, file path is missing!", Toast.LENGTH_LONG).show();
          }
  
          btnUpload.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // uploading the file to server
                  new UploadFileToServer().execute();
              }
          });
  
      }
  
      /**
       * Displaying captured image/video on the screen
       * */
      private void previewMedia() {
  
  
              vidPreview.setVisibility(View.VISIBLE);
              vidPreview.setVideoPath(filePath);
              // start playing
              vidPreview.start();
  
      }
  
      /**
       * Uploading the file to server
       * */
      public class UploadFileToServer extends AsyncTask&lt;Void, Integer, String&gt; {
          @Override
          protected void onPreExecute() {
              // setting progress bar to zero
              progressBar.setProgress(0);
              super.onPreExecute();
          }
  
          @Override
          protected void onProgressUpdate(Integer... progress) {
              // Making progress bar visible
              progressBar.setVisibility(View.VISIBLE);
  
              // updating progress bar value
              progressBar.setProgress(progress[0]);
  
              // updating percentage value
              txtPercentage.setText(String.valueOf(progress[0]) + "%");
          }
  
          @Override
          protected String doInBackground(Void... params) {
              return uploadFile();
          }
  
          @SuppressWarnings("deprecation")
          public String uploadFile() {
              String responseString = null;
  
              HttpClient httpclient = new DefaultHttpClient();
              HttpPost httppost = new HttpPost(Config.FILE_UPLOAD_URL);
  
              try {
  
                  AndroidMultiPartEntity entity = new AndroidMultiPartEntity(
                          new AndroidMultiPartEntity.ProgressListener() {
  
                              @Override
                              public void transferred(long num) {
                                  publishProgress((int) ((num / (float) totalSize) * 100));
                              }
                          });
                  File sourceFile = new File(filePath);
  
                  // Adding file data to http body
                  entity.addPart("video", new FileBody(sourceFile));
                  totalSize = entity.getContentLength();
                  httppost.setEntity(entity);
                  // Making server call
                  HttpResponse response = httpclient.execute(httppost);
                  HttpEntity r_entity = response.getEntity();
  
                  int statusCode = response.getStatusLine().getStatusCode();
                  if (statusCode == 200) {
                      // Server response
                      Bitmap thumb = ThumbnailUtils.createVideoThumbnail(filePath,
                              MediaStore.Images.Thumbnails.MINI_KIND);
                      ByteArrayOutputStream stream = new ByteArrayOutputStream();
                      thumb.compress(Bitmap.CompressFormat.JPEG, 100, stream);
                      byte[] thumbnailBitmapBytes = stream.toByteArray();
  
                      db=openOrCreateDatabase("TwentyThree", Context.MODE_PRIVATE, null);
  
                      SQLiteStatement stmt = db.compileStatement("INSERT INTO videos (path, thumbnail) values (?, ?)");
                      stmt.bindString(1, serverPath);
                      stmt.bindBlob(2, thumbnailBitmapBytes);
                      stmt.executeInsert();
  
  
                      responseString = EntityUtils.toString(r_entity);
                  } else {
                      responseString = "Error occurred! Http Status Code: "
                              + statusCode;
                  }
  
              } catch (ClientProtocolException e) {
                  responseString = e.toString();
              } catch (IOException e) {
                  responseString = e.toString();
              }
  
              return responseString;
  
          }
  
          @Override
          protected void onPostExecute(String result) {
              Log.e(TAG, "Response from server: " + result);
  
              // showing the server response in an alert dialog
              showAlert(result);
  
              super.onPostExecute(result);
          }
  
      }
  
      /**
       * Method to show alert dialog
       * */
      private void showAlert(String message) {
          AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setMessage(message).setTitle("Response from Servers")
                  .setCancelable(false)
                  .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int id) {
                          UploadActivity.this.finish();
                      }
                  });
          AlertDialog alert = builder.create();
          alert.show();
      }
  
  }
  </code></pre>
  
  <p>Edit 2:
  <img src="https://i.stack.imgur.com/C583q.png" alt="enter image description here"></p>