Put the following 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 ".