Less nonsense, directly on the code:
<?php
/**
* note:for octet-stream Upload
* This is a streaming upload php file * Please be amended accordingly to on the
AC tual 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 standard form upload PHP file * Please be amended accordingly to based on the Actua L 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 all
oWS ';
Break
Case 2: $error _log = ' The ' the ' bigger than ' '
Break
Case 3: $error _log = ' Only part of the file is uploaded ';
Break
Case 4: $error _log = ' No file is 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 = ' on
ly 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 picture save path, which is saved by default in the directory where the code resides (can modify the save path according to actual requirements) $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: US Mito offers two upload interfaces for testing
One is octet-stream way upload, address: http://imgkaka.meitu.com/xiuxiu_web_pic_save.php
Another is the multipart/form-data way to upload, the address is: http://web.upload.meitu.com/image_upload.php
table single-name called "Upload_file."