日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

PHP流式上传和表单上传(美图秀秀)

發布時間:2023/11/29 php 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PHP流式上传和表单上传(美图秀秀) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近需要開發一個頭像上傳的功能,找了很多都需要授權的,后來找到了美圖秀秀,功能非常好用。

<?php /*** Note:for octet-stream upload* 這個是流式上傳PHP文件* 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* 這個是標準表單上傳PHP文件* 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!'); }// 圖片保存路徑,默認保存在該代碼所在目錄(可根據實際需求修改保存路徑) $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 ();

?

備注:美圖秀秀提供兩個上傳接口供測試

一個是octet-stream方式上傳,地址為:http://imgkaka.meitu.com/xiuxiu_web_pic_save.php

另一個是multipart/form-data方式上傳,地址為:http://web.upload.meitu.com/image_upload.php

表單名稱為"upload_file" 。

轉載于:https://www.cnblogs.com/52php/p/5675325.html

總結

以上是生活随笔為你收集整理的PHP流式上传和表单上传(美图秀秀)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。