Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
155 views
in Technique[技术] by (71.8m points)

issue for received image in php with upload script Android

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...