Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I use this code for upload image: http://vikaskanani.wordpress.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-part/

I replaced

bm = BitmapFactory.decodeFile("/data/data/fshizzle.com/files/image.jpg");

and

HttpPost postRequest = new HttpPost("http://10.0.2.2/upload.php");

it's all!

I can not receved info in php file I use this code php work if use html code

<form method="POST" action="upload.php" enctype="multipart/form-data">
     <!-- On limite le fichier à 100Ko -->
     <input type="hidden" name="MAX_FILE_SIZE" value="100000">
     Fichier : <input type="file" name="avatar">
     <input type="submit" name="envoyer" value="Envoyer le fichier">
</form>

CODE PHP:

$dossier = './upload/';
$fichier = basename($_FILES['sfsdfsdf']['name']);
if(move_uploaded_file($_FILES['sfsdfsdf']['tmp_name'], $dossier . $fichier)) 
//Si la fonction renvoie TRUE, c'est que ?a a fonctionné...
{
     echo 'Upload effectué avec succès !';
}
else //Sinon (la fonction renvoie FALSE).
{
     echo '<br>Echec de l'upload !';
}

a simple if(isset($_FILES['sfsdfsdf'])) don't work what is a good code?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
149 views
Welcome To Ask or Share your Answers For Others

1 Answer

If I understand your problem then I had the same thing yesterday. From the code you provided it seems like they have left out some crucial parts, such as the enctype. If you google upload image to php from android there are some better examples.

If you chose to do it this way make sure that your server-side permissions are set to allow php to create, write, and/or read files for whatever directory you are using. I found this method to be a real pain, and found it was much simpler to convert the image to base64 and send that as a string to the server, and have php create a file using the base64 string. If you can't figure out how to do that (google) let me know and I'll see if I could send you some code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...