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?