使用 Snoopy 代理异步文件上传
程序员文章站
2024-02-01 11:28:04
...
使用 formdata 结合 snoopy 做请求转发,实现非 form 形式,非 iframe 形式的异步文件上传功能。
JS 代码:
document.getElementById('#file').change = function (e) {
var data = new FormData();
//设置参数
data.append('nick', '邦彦');
data.append('session_id', '6fc373162b5e8a78a255777e0108a0b3');
data.append('file', e.currentTarget.files[0]);
}
PHP 代码:
require('Snoopy.class.php');
$action = 'http://localhost/upload.php';
$snoopy = new Snoopy();
$snoopy->_submit_type = 'multipart/form-data';
$snoopy->submit($action, $_REQUEST, $_FILES);
echo $snoopy->results;
// Downloads By http://www.bkjia.com
JS 代码:
document.getElementById('#file').change = function (e) {
var data = new FormData();
//设置参数
data.append('nick', '邦彦');
data.append('session_id', '6fc373162b5e8a78a255777e0108a0b3');
data.append('file', e.currentTarget.files[0]);
}
PHP 代码:
require('Snoopy.class.php');
$action = 'http://localhost/upload.php';
$snoopy = new Snoopy();
$snoopy->_submit_type = 'multipart/form-data';
$snoopy->submit($action, $_REQUEST, $_FILES);
echo $snoopy->results;
// Downloads By http://www.bkjia.com
上一篇: php随机数字代码_PHP教程
下一篇: Ubuntu下MySQL重装问题