How to Use thinkphp in the app to upload images

Source: Internet
Author: User
In the last appIOS real-name authentication using the thinkphp write interface, you must upload a picture of yourself. How can I use thinkphp to write the upload image? Is there any source code? Please note every step. Thank you !! You must upload an image of your own for real-name authentication using the thinkphp write interface of the latest IOS app.
Thank you very much for every step of writing source code to upload images using thinkphp !!

Reply content:

You must upload an image of your own for real-name authentication using the thinkphp write interface of the latest IOS app.
Thank you very much for every step of writing source code to upload images using thinkphp !!

// The upload image method can be placed in the parent class for future inheritance and direct calling
// Two upload Methods: file and base64

Public function picupload () {if (! IS_POST) {die ('');} // base64 upload mode (mainly for processing input file not supported) $ smeta =$ _ POST ['smeta ']; if (preg_match ('/^ (data: \ s * image \/(\ w +); base64,)/', $ smeta, $ result )) {// base64 upload $ data = base64_decode (str_replace ($ result [1], '', $ smeta); $ dataname = '. /Uploads /'. uniqid (). '. '. $ result [2]; if (file_put_contents ($ dataname, $ data) {$ this-> ajaxoutput ($ dataname ); // The returned data structure is self-encapsulated} else {$ this-> ajaxerror ('upload error ');} // Process file Upload. Here we call thinkphp to encapsulate \ Think \ Upload. You can learn how to write the thinkphp official class. $ config = array ('rootpath' => '. /Uploads/', 'savepath' => '', 'maxsize' => 11048576, 'savename' => array ('uniqid ',''), 'exts' => array ('jpg ', 'gif', 'png', 'jpeg '), 'autosub' => false ,); $ upload = new \ Think \ Upload ($ config); // $ info = $ upload-> upload (); // start to upload if ($ info) {// uploaded successfully $ first = array_shift ($ info); if (! Empty ($ first ['url']) {$ url = $ first ['url'];} else {$ url = C ("tmpl_parse_string.w.upload __"). $ first ['savename'];} $ this-> ajaxoutput ($ url);} else {// Upload Failed, returned error $ this-> ajaxerror ($ upload-> getError ());}}

App post
And then $ _ FILES in php receive, there is no special

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.