先上个效果图:
Sample6_1.php 中创建Form:
//显示上传状态和图片
//上传文件需要定义enctype,为了显示图片将target设为uploadframe
上传图片函数 uploadimg:
//上传文件需要定义enctype,为了显示图片将target设为uploadframe
上传图片函数 uploadimg:
function uploadimg(theform){
//提交Form
theform.submit();
//在showimg
//提交Form
theform.submit();
//在showimg
中显示上传状态
setStatus ("Loading...","showimg");
}
//上传状态函数
function setStatus (theStatus,theObj){
obj = document.getElementById(theObj);
if (obj){
obj.innerHTML = "
process_upload.php 提供文件上传功能:
setStatus ("Loading...","showimg");
}
//上传状态函数
function setStatus (theStatus,theObj){
obj = document.getElementById(theObj);
if (obj){
obj.innerHTML = "
";
}
}
}
}
process_upload.php 提供文件上传功能:
//提供图片类型校验
$allowedtypes = array("image/jpeg","image/pjpeg","image/png","image/x-png","image/gif");
//文件存放目录
$savefolder = "images"; //如果有文件上传就开始干活
if (isset ($_FILES['myfile'])){
//检查上传文件是否符合$allowedtypes类型
if (in_array($_FILES['myfile']['type'],$allowedtypes)){
if ($_FILES['myfile']['error'] == 0){
$thefile = "$savefolder/".$_FILES['myfile']['name'];
//通过move_uploaded_file上传文件
if (!move_uploaded_file($_FILES['myfile']['tmp_name'],$thefile)){
echo "There was an error uploading the file.";
}
else{
?>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
$allowedtypes = array("image/jpeg","image/pjpeg","image/png","image/x-png","image/gif");
//文件存放目录
$savefolder = "images"; //如果有文件上传就开始干活
if (isset ($_FILES['myfile'])){
//检查上传文件是否符合$allowedtypes类型
if (in_array($_FILES['myfile']['type'],$allowedtypes)){
if ($_FILES['myfile']['error'] == 0){
$thefile = "$savefolder/".$_FILES['myfile']['name'];
//通过move_uploaded_file上传文件
if (!move_uploaded_file($_FILES['myfile']['tmp_name'],$thefile)){
echo "There was an error uploading the file.";
}
else{
?>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
相关文章
IE6是一个非常老旧的网页浏览器,虽然现在很少人再使用它,但...
PHP中的count()函数是用来计算数组或容器中元素的个数。这个...
使用 AJAX(Asynchronous JavaScript and XML)技术可以在不...
Ajax(Asynchronous JavaScript and XML)是一种用于改进网页...
本文将介绍如何通过AJAX下载Excel文件流。通过AJAX,我们可以...
Ajax是一种用于客户端和服务器之间的异步通信技术。通过Ajax...