热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

jsphpxmlrequest上传图片

php教程|php手册xhr,height,var,function,createXMLHttpReqphp教程-php手册本来想用插件上传图片的,后来自己写了一个简单的js实现异

php教程|php手册js php xmlrequest 上传图片
xhr,height,var,function,createXMLHttpReq
php教程-php手册
本来想用插件上传图片的,后来自己写了一个简单的js实现异步的图片上传,不多说上代码非常简单
网狐荣耀lua 源码,ubuntu中命令rm,tomcat传值中文乱码,爬虫技术法律,php下载文件功能,学电脑seolzw
upload.php
机锋市场 源码,vscode删除空行视频,ubuntu扩展 空间,监听tomcat服务脚本,立春的爬虫和端午的爬虫,php while 嵌套,贵州seo网络推广平台,企业网站源码生成,destoon 后台模板lzw
结婚网站源码,vscode怎么复制一行,ubuntu 各种指令,tomcat增量部署项目,斯巴达python爬虫,php调用函数外的变量,平山工商seo技术售后服务lzw
if(isset($_FILES[“myfile”]))
{
$ret = array();
$uploadDir = ‘images’.DIRECTORY_SEPARATOR.date(“Ymd”).DIRECTORY_SEPARATOR;
$dir = dirname(__FILE__).DIRECTORY_SEPARATOR.$uploadDir;
file_exists($dir) (mkdir($dir,0777,true) && chmod($dir,0777));
if(!is_array($_FILES[“myfile”][“name”])) //single file
{
$fileName = time().uniqid().’.’.pathinfo($_FILES[“myfile”][“name”])[‘extension’];
move_uploaded_file($_FILES[“myfile”][“tmp_name”],$dir.$fileName);
$ret[‘file’] = DIRECTORY_SEPARATOR.$uploadDir.$fileName;
}
echo json_encode($ret);
}

?>

index.html


var xhr;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xhr = new ActiveXObject(“Microsoft.XMLHTTP”);
}
else if(window.XMLHttpRequest)
{
xhr = new XMLHttpRequest();
}
}

function UpladFile()
{
var fileObj = document.getElementById(“file”).files[0];
var FileCOntroller= ‘upload.php’;
var form = new FormData();
form.append(“myfile”, fileObj);
createXMLHttpRequest();
xhr.Onreadystatechange= handleStateChange;
xhr.open(“post”, FileController, true);
xhr.send(form);
}

function handleStateChange()
{
if(xhr.readyState == 4)
{
if (xhr.status == 200 xhr.status == 0)
{
var result = xhr.responseText;
var json = eval(“(” + result + “)”);
alert(‘图片链接:\n’+json.file);
}
}
}

.txt{ height:28px; border:1px solid #cdcdcd; width:670px;}
.mybtn{ background-color:#FFF; line-height:14px;vertical-align:middle;border:1px solid #CDCDCD;height:30px; width:70px;}
.file{ position:absolute; top:0; right:80px; height:24px; filter:alpha(opacity:0);opacity: 0;width:260px }


浏览…

上传


推荐阅读
author-avatar
0519bobo_724
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有