US Mito web open platform--php streaming upload and form upload sample sharing _php instance

Source: Internet
Author: User

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

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.