In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "how to upload a picture to PHP in android", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to upload pictures to PHP in android" article.
The copy code is as follows:
[java] view plaincopyprint?
/ / set the timeout
Httpclient.setTimeout (20000)
Again building,runing, still can't. This is strange, obviously good, how can suddenly become a connection timeout! After tossing about for a while, he also communicated with his friends backstage, and he also tested the upload interface and found that there was no problem, so he let me go by myself.
I was depressed. I couldn't see what was wrong with the original code, and there was nothing I could do about it, so I came up with the worst way to build a PHP interface to upload pictures and personally test what was going on.
1. First of all, you need the next convenient and fast PHP server, I use WampServer here, Baidu-download-install-start, browser input: http://127.0.0.1 has a page display, OK. It's that simple!
two。 Browser input: enter the local IP address of http:// and report an error. Similar to "You don't have permission to access / on this server", it means that your WM has not been set yet. You need to make the following settings:
The reason for this problem is that the default configuration in Apache's http.conf is
The copy code is as follows:
# onlineoffline tag-don't remove
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Only 127.0.0.1 access is allowed. Click the wampserver icon and then click the above default configuration in Putonline,http.conf to automatically change to
The copy code is as follows:
# onlineoffline tag-don't remove
Order Allow,Deny
Allow from all
Now the localhost can be accessed.
Similarly, phpMyadmin cannot be accessed normally under localhost and can be accessed normally at 127.0.0.1. The solution:
Click the alias directory under the root directory, open the phpmyadmin.conf configuration file, and change the http.conf as above
The copy code is as follows:
Deny from all
Allow from 127.0.0.1
Modify to
Allow from all
3. Then enter: http:// native IP address enter display page OK! As for why the second step and the third step, I will not talk about it. Leave it to the newcomers to think about it! The god just ignored it.
4. Write a PHP file for uploading pictures. Of course, how can I, a child who taps java, suddenly come out? what to do? of course, Baidu refers to others. The following PHP code comes from the network, and there is no error in personal test:
[php] view plaincopyprint?
5. Put the above php file in the www directory under the WM installation directory, as shown in my figure below, for reference only:
6. After the above steps, the PHP end has been built. Now it is time to go back to the Android side to change the IP address and test the oK. The code snippet is as follows:
[java] view plaincopyprint? / / HTTP upload picture RequestParams params = new RequestParams (); try {/ / save compressed bitmap as image file String saveImgPath=getSD_Path () + "/ saveimg.png"; File saveimg=new File (saveImgPath); FileOutputStream fos = new FileOutputStream (saveimg); bmp.compress (Bitmap.CompressFormat.PNG, 100k, fos); fos.flush (); fos.close (); / / upload compressed file, about 100k File uploadImg=new File (saveImgPath) Params.put ("attach", uploadImg);} catch (FileNotFoundException e) {e.printStackTrace ();} catch (IOException e) {e.printStackTrace ();} / / upload address String url=URLConfigs.UploadHeadImage_ukey+myprefs.Ukey (). Get (); String url= "http://192.168.0.8/upload.php"; LogUtil.e (TAG," upload img url: "+ url) AsyncHttpUtil.post_loading (context,url, params, new MyTextHttpResponseHandler () {@ Override public void onSuccess (int status, Header [] arg1, String json) {super.onSuccess (status, arg1, json); LogUtil.e (TAG, "upload json:" + json); RespondBaseEntity entity=GsonUtil.GetFromJson (json, RespondBaseEntity.class); if (entity.isStatus ()) {/ / upload successfully, set image face.setImageBitmap (bmp) ToastUtils.show (context, "upload successful");} else {ToastUtils.show (context, json);} myprefs.position (). Put (0);} @ Override public void onFailure (int arg0, Header [] arg1, String arg2, Throwable arg3) {super.onFailure (arg0, arg1, arg2, arg3); myprefs.position (). Put (0); arg3.printStackTrace () ToastUtils.show (context, R.string.network_unavailable);}
Params.put ("attach", uploadImg); the attach parameter here corresponds to the server one by one, so don't change it.
String url= "http://192.168.0.8/upload.php"; this 192.168.0.8 is the address of my PHP deployment, just change it to your own.
PS: don't commit 2, use 127.0.0.1. Think about why you can't use 127.0.0.1.
This is building,runing. Found OK... You can upload it and find the upload directory in the www directory. There are uploaded pictures in the upload directory.
The above is about the content of this article on "how to upload pictures to PHP in android". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.