Ask the app to upload images. how does php receive and process images (using TP)

Source: Internet
Author: User
Ask the app to upload images. php has checked a lot of information on the Internet for receiving and processing (using TP,
Some use base64
Some use $ _ FILES;
($ _ POST;
File_get_contents ('php: // input ')

Can I simulate an example of a client Upload and PHP backend processing?
I don't quite understand the principle. thank you.

Reply to discussion (solution)

Can I use the upload class provided by tp itself? Changed to interface

Class UserAction extends Action {// add public function add () {// var_dump (uniqid (). (time (). rand (0,100); // die (); import ('org. net. uploadFile '); $ upload = new UploadFile (); // instantiate the upload class $ upload-> maxSize = 3145728; // Set the attachment upload size $ upload-> allowExts = array ('jpg ', 'GIF', 'PNG', 'jpeg '); // Set the attachment upload type // $ upload-> saveRule = uniqid; // the image name can be changed at the same time, different image names will not be overwritten. $ upload-> saveRule = 'mytime'; $ upload-> SavePath = './Public/Uploads/'; // Set the attachment Upload directory if (! $ Upload-> upload () {// upload error message $ this-> error ($ upload-> getErrorMsg ());} else {// obtain the information of the uploaded file after the upload is successful $ info = $ upload-> getUploadFileInfo ();} $ user = M ('user'); $ user-> create (); // create a data object $ user-> user_pic = "http ://". $ this-> _ server ('http _ host '). '/Public/Uploads /'. $ info [0] ['savename']; // Save the uploaded photo and assemble it as needed $ user-> user_idcard = "http ://". $ this-> _ server ('http _ host '). '/Public/Uploads /'. $ info [1] ['savename']; $ use R-> user_card = "http ://". $ this-> _ server ('http _ host '). '/Public/Uploads /'. $ info [2] ['savename']; // $ user-> piclink = "http ://". $ this-> _ server ('http _ host '). '/Public/Uploads /'. $ info [0] ['savename']; // $ user-> time = date ('Y-m-d H: I: S ', time (); $ user-> add (); // echo $ flash-> getlastsql (); // die (); $ this-> success ("data is saved successfully! ");}

How can I test it? must I use a client to submit it? Do you want to simulate the data? Thank you.

Our app uploads images over http. during the test, we use the form and set the form attribute to enctype = "multipart/form-data"
$ _ FILES can be used for background retrieval.

What is the format used for uploading images to the app front-end? Consult

Then you have to ask the app developer how to upload images. Generally, they all use http form uploads. that is to say, you use formYou can simulate app upload.
Of course, you can also print the data in $ _ FILES. If yes, it indicates that the image uploaded by the app has been obtained. If no, it will fail.

App Upload. php does not need to modify the received content, just like webpage Upload.
The app uses content-disposition: form-data to upload data.

The PHP terminal acquisition method is determined based on the APP Upload method. most of them are form-based uploads.
$ _ FILES; file_get_contents ('php: // input ..

Some of them read the file content on the client first, then encoded in base64, and then uploaded.
Simple resumable Upload of large files can be [mainly handled by the APP ].

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: 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.