title: uploading file in java via php
body: <p>i'm trying to upload a file on my php server using java,but my httprequest fails every time i run the code,i don't know what is its cause,first i thought it may be caused by the multipartEnttity method whose parameters i left empty earlier,but now after filling it the same problem still ocurrs....</p>
  
  <pre><code>    //this is my java code
  
      String path="E:\\upload.txt";
      HttpClient hc=new DefaultHttpClient();
      hc.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
      HttpPost hp=new HttpPost("http://localhost/shoolPHP/uploadFile.php");
      File f=new File(path);
      MultipartEntity me=new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
      ContentBody cf=new FileBody(f);
      me.addPart("userfile", cf);
      hp.setEntity(me);
      System.out.println("executing request" +hp.getRequestLine());
      HttpResponse hr=hc.execute(hp);
      HttpEntity he=hr.getEntity();
  
      if(!(hr.getStatusLine().toString()).equals("HTTP/1.1 200 OK")){
          System.out.println("Uploaded");
      }
      else{
          System.out.println("Failed");
  
  
      }
      System.out.println(hr.getStatusLine());
      if (he != null) {
          System.out.println(EntityUtils.toString(he));
      }
      if (he != null) {
          he.consumeContent();
      }
      hc.getConnectionManager().shutdown();
  </code></pre>
  
  <p>//this is corrected php code</p>
  
  <pre><code>  &lt;?php
  
    $uploads_dir='/Home';
    if(is_uploaded_file($_FILES['userfile']['tmp_name'])){
     $dest=$_FILES['userfile']['name'];
    echo "File" .$_FILES['userfile']['name'] ."uploaded file successfully to
    $uploads_dir/$dest";
  
    move_uploaded_file ($_FILES['userfile'] ['tmp_name'],  "$uploads_dir/$dest");
    } else {
    echo "Possible file upload attack: ";
    echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
    print_r($_FILES);
    }
    ?&gt;
  </code></pre>
  
  <p>//these are the new warnings</p>
  
  <p>executing requestPOST <a href="http://localhost/shoolPHP/uploadFile.php" rel="nofollow">http://localhost/shoolPHP/uploadFile.php</a> HTTP/1.1
  Uploaded
  HTTP/1.1 200 OK
  Fileupload.txtuploaded file successfully to
  /Home/upload.txt<br />
  <b>Warning</b>:  move_uploaded_file(/Home/upload.txt): failed to open stream: No such file or directory in <b>C:\xampp\htdocs\shoolPHP\uploadFile.php</b> on line <b>9</b><br />
  <br />
  <b>Warning</b>:  move_uploaded_file(): Unable to move 'C:\xampp\tmp\phpB374.tmp' to '/Home/upload.txt' in <b>C:\xampp\htdocs\shoolPHP\uploadFile.php</b> on line <b>9</b><br /></p>