Meitu Xiuxiu web open platform-PHP streaming Upload and form Upload example sharing _ PHP Tutorial

Source: Internet
Author: User
Tags upload php
Meitu Xiuxiu web open platform-PHP streaming Upload and form Upload example sharing. Put it bluntly, put the code directly: php *** Note: foroctet-streamupload * This is the stream Upload php file ** Pleasebeamendedaccordinglybasedontheactualsituation * $ post_input. put the code directly:

<? Php/*** Note: for octet-stream upload * This is the php file for streaming upload * Please be amended accordingly based on the actual situation */$ post_input = 'php: // input '; $ save_path = dirname (_ FILE _); $ postdata = file_get_contents ($ post_input); if (isset ($ postdata) & strlen ($ postdata)> 0) {$ filename = $ save_path. '/'. uniqid (). '.jpg '; $ handle = fopen ($ filename, 'W +'); fwrite ($ handle, $ postdata); fclose ($ handle); if ( Is_file ($ filename) {echo 'image data save successed, file: '. $ filename; exit () ;} else {die ('image upload error! ') ;}} Else {die ('image data not detected! ');}

<? Php/*** Note: for multipart/form-data upload * This is the php file uploaded from the standard form * Please be amended accordingly based on the actual situation */if (! $ _ FILES ['filedata']) {die ('image data not detected! ');} If ($ _ FILES ['filedata'] ['error']> 0) {switch ($ _ FILES ['filedata'] ['error']) {case 1: $ error_log = 'The file is bigger than this PHP installation allows '; break; case 2: $ error_log = 'The file is bigger than this form allows'; break; case 3: $ error_log = 'only part of the file was uploaded'; break; case 4: $ error_log = 'No file was uploaded'; break; default: break ;} die ('upload error :'. $ Error_log);} else {$ img_data = $ _ FILES ['filedata'] ['tmp _ name']; $ size = getimagesize ($ img_data ); $ file_type = $ size ['Mime ']; if (! In_array ($ file_type, array ('image/jpg ', 'image/jpeg', 'image/pjpeg ', 'image/png', 'image/GIF '))) {$ error_log = 'only allow jpg, png, gif '; die ('upload error :'. $ error_log);} switch ($ file_type) {case 'image/jpg ': case 'image/jpeg': case 'image/pjpeg ': $ extension = 'jpg '; break; case 'image/png ': $ extension = 'PNG'; break; case 'image/GIF': $ extension = 'GIF'; break;} if (! Is_file ($ img_data) {die ('image upload error! ');} // The image storage path, which is saved in the directory where the code is located by default (you can modify the storage path as needed) $ save_path = dirname (_ FILE __); $ uinqid = uniqid (); $ filename = $ save_path. '/'. $ uinqid. '. '. $ extension; $ result = move_uploaded_file ($ img_data, $ filename); if (! $ Result |! Is_file ($ filename) {die ('image upload error! ');} Echo 'image data save successed, file:'. $ filename; exit ();

Note: Meitu Xiuxiu provides two Upload interfaces for testing.
One is the octet-stream mode Upload, address: http://imgkaka.meitu.com/xiuxiu_web_pic_save.php
The other is multipart/form-data upload, address: http://web.upload.meitu.com/image_upload.php
The form name is "upload_file ".

Using php/*** Note: for octet-stream upload * This is the php file for streaming upload * Please be amended accordingly based on the actual situation */$ post_input...

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.