php文件上传接口及文件上传错误服务器配置
2013-12-25 21:08
253 查看
一:上传表单
二:上传处理文件php
三:常见错误配置
其中$_FILES['userfile']['error']的可以有下列取值和意义:
0——没有错误发生,文件上传成功。
1——上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值。
2——上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值。
3——文件只有部分被上传。
4——没有文件被上传。
参考:http://www.chinaunix.net/old_jh/27/667690.html
<form enctype="multipart/form-data" action="doFileUp.php" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> --> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="file" type="file" /> <input type="submit" value="Send File" /> </form>
二:上传处理文件php
<?php //file dir $uploaddir = 'upload/'; //file name $uploadfile = $uploaddir . basename($_FILES['file']['name']); //upload result $result = array(); //begain upload if ($_FILES["file"]["error"] > 0) { $error = "file upload error"; array_push($result,0,$error,$_FILES); } else { if (file_exists("upload/" . $_FILES["file"]["name"])) { echo json_encode($_FILES["file"]["name"] . " already exists. "); } else { move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]); $error = "file upload success"; array_push($result,1,$error,$_FILES); } } echo json_encode($result); ?>
三:常见错误配置
其中$_FILES['userfile']['error']的可以有下列取值和意义:
0——没有错误发生,文件上传成功。
1——上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值。
2——上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值。
3——文件只有部分被上传。
4——没有文件被上传。
参考:http://www.chinaunix.net/old_jh/27/667690.html
相关文章推荐
- php tp3.2 thinkphp3.2文件上传error错误代码-具体详情
- php文件上传错误代码
- 七牛整合php上传从微信下载接口下载下来的文件
- 关于 PHP 文件上传错误代码 UPLOAD_ERR_PARTIAL: 3 解决办法
- PHP文件上传($_FILES)错误信息说明
- php文件上传错误代码
- php 文件上传 错误信息 总结 $_FILES['Filedata']["error"] 值枚举
- php中文件上传$_FILES 的错误代码
- php文件上传错误代码
- PHP文件上传错误类型及说明
- PHP文件上传、客户端和服务器端加限制、抓取错误信息、完整步骤解析
- php文件上传 [function.move-uploaded-file]: failed to open stream 错误解决办法
- C# 使用HttpWebRequest通过PHP接口 上传文件
- php文件上传错误代码
- php文件上传错误代码 解释 PHP文件上传注意事项
- php文件上传接口
- php中利用curl访问接口、上传文件
- php文件上传错误代码
- PHP上传文件详解 错误提示
- PHP -- 上传文件接口编写 及 iOS -- 端上传图片AF实现