请教app上传图片,php如何接收处理 (用的TP)
网上查了好多资料,
有的用base64
有的用 $_FILES;
($_POST;
file_get_contents('php://input')
有没有可以模拟出来一个客户端上传, 然后 PHP后端处理完成的例子?
不是很明白原理,谢谢
回复讨论(解决方案)
用tp本身自带的上传类,不行吗?改成接口
class UserAction extends Action{ //添加 public function add(){ // var_dump(uniqid().(time().rand(0,100))); // die(); import('ORG.Net.UploadFile'); $upload = new UploadFile();// 实例化上传类 $upload->maxSize = 3145728 ;// 设置附件上传大小 $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型 //$upload->saveRule = uniqid;//这个是改变图片名称的,可同时改变多张图片的名称,实现图片的不同名 这样也就不会出现覆盖的现象了 $upload->saveRule='mytime'; $upload->savePath = './Public/Uploads/';// 设置附件上传目录 if(!$upload->upload()) {// 上传错误提示错误信息 $this->error($upload->getErrorMsg()); }else{// 上传成功 获取上传文件信息 $info = $upload->getUploadFileInfo(); } $user = M('user'); $user->create(); // 创建数据对象 $user->user_pic = "http://".$this->_server('HTTP_HOST').'/Public/Uploads/'.$info[0]['savename']; // 保存上传的照片根据需要自行组装 $user->user_idcard = "http://".$this->_server('HTTP_HOST').'/Public/Uploads/'.$info[1]['savename']; $user->user_card = "http://".$this->_server('HTTP_HOST').'/Public/Uploads/'.$info[2]['savename']; //$user->piclink = "http://".$this->_server('HTTP_HOST').'/Public/Uploads/'.$info[0]['savename']; // //$user->time = date('Y-m-d H:i:s',time()); $user->add(); // echo $flash->getlastsql(); // die(); $this->success("数据保存成功!"); }
如何测试,必须用客户端来提交吗?好模拟出数据来不?谢谢
我们的app上传图片使用http上传的,我测试时,用的form表单,设置form属性为enctype="multipart/form-data"
后台获取用$_FILES就可以获取了
怎么看 app前端上传图片用的什么格式啊? 请教
那就得问开发app的人怎么上传图片的,一般都是http 表单上传,也就是说,你用form表单的就能模拟app上传了
当然,你也可以,打印出$_FILES里面的数据,若有,就表示获取到了app上传的图片,没有就失败了呗
app上传,php这边接收不用改的,与网页上传一样。
app那边使用 content-disposition: form-data; 这种方式上传就可以了。
参考: http://blog.csdn.net/fdipzone/article/details/12180523
根据APP的上传方式来决定PHP端的获取方式,多数都是表单式上传。
$_FILES; file_get_contents('php://input')都可以。。
还有的是先在客户端读取了文件内容,再base64编码,再上传。
比较简单的大文件断点上传,其实就可以这种【主要靠APP处理】。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio
