One of my friends is trying to follow Sony Ericsson tutorial on HTTP document upload from mobile device through Java Microedition.
Here is an HTML example.

<form action="http://myserver/post.php" enctype ="multipart/form-data" method="post">
<input type="file" name="uploadedfile">
<input type="submit">
</form>

Here is the php file receiving the posted file.

//post.php
<?php

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

?>

However when reading server respond we get following

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>411 Length Required</TITLE>
</HEAD><BODY>
<H1>Length Required</H1>
A request of the requested method POST requires a valid Content-length.<P>
chunked Transfer-Encoding forbidden: /system-bin/php4exe/rest/post-azza-image/index.php<P>
</BODY></HTML>

It does complain about Content-Length, but I provided this data as conn.setRequestProperty("Content-Length", Integer.toString((message1.length() + message2.length() + imgData.length))); where

message1.length() = 152
message2.length() = 48
imgData.length = 431

Total lenght = 735

From my point of view (as PHP ignorant) this seems to be some configuration issue where something need to be enabled either in PHP or sever configuration.

Any suggestions?

If you look in your PHP.ini configuration then the default limit for uploads is 2 Meg, a request larger than 2 meg (Including images, files, text, headers) could return that error

Well just as another validator option, try making your php file the following:

<?php
 
$target_path = "uploads/";
 
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if (!empty($_FILES)) {
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ".  basename( $_FILES['uploadedfile']['name']).
        " has been uploaded";
    } else{
        echo "There was an error uploading the file, please try again!";
    }
}
?>
This article has been dead for over six months. Start a new discussion instead.