当前位置: 首页 > news >正文

网站导航栏分析sem是什么意思?

网站导航栏分析,sem是什么意思?,php网站建设案例,怎么创建网站建设phphtmljsajax实现文件上传 目录 一、表单单文件上传 1、上传页面 2、接受文件上传php 二、表单多文件上传 1、上传页面 2、接受文件上传php 三、表单异步xhr文件上传 1、上传页面 2、接受文件上传php 四、表单异步ajax文件上传 1、上传页面 2、接受文件上传ph…

php+html+js+ajax实现文件上传

目录

一、表单单文件上传

1、上传页面

2、接受文件上传php

二、表单多文件上传

1、上传页面

2、接受文件上传php 

三、表单异步xhr文件上传

1、上传页面

2、接受文件上传php  

四、表单异步ajax文件上传 

1、上传页面

2、接受文件上传php   


一、表单单文件上传
1、上传页面
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<head><title>文件上传</title>
</head>
<body>
<h1>文件上传</h1>
<form action="upload.php" method="POST" enctype="multipart/form-data"><input type="file" name="fileToUpload"><input type="submit" value="上传文件">
</form>
</body>
</html>
2、接受文件上传php
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {$targetDir = "uploads/"; // 上传文件保存的目录$targetFile = $targetDir . basename($_FILES["fileToUpload"]["name"]);$uploadOk = 1; // 上传状态,1表示成功,0表示失败$imageFileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION)); // 上传文件的扩展名// 检查文件是否为真实的图像文件if (isset($_POST["submit"])) {$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);if ($check !== false) {echo "文件是一个有效的图像 - " . $check["mime"] . ".";$uploadOk = 1;} else {echo "文件不是一个有效的图像.";$uploadOk = 0;}}// 检查文件是否已存在if (file_exists($targetFile)) {echo "对不起,文件已存在.";$uploadOk = 0;}// 检查文件大小if ($_FILES["fileToUpload"]["size"] > 500000) {echo "对不起,文件太大.";$uploadOk = 0;}// 允许上传的文件格式$allowedExtensions = array("jpg", "jpeg", "png", "gif");if (!in_array($imageFileType, $allowedExtensions)) {echo "对不起,仅允许上传 JPG, JPEG, PNG 和 GIF 文件.";$uploadOk = 0;}// 检查上传状态if ($uploadOk == 0) {echo "对不起,文件上传失败.";} else {if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $targetFile)) {echo "文件上传成功.";} else {echo "对不起,文件上传失败.";}}
}
?>

 

二、表单多文件上传
1、上传页面
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<head><title>文件上传示例</title>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data"><input type="file" name="files[]" multiple><input type="submit" value="上传文件">
</form>
</body>
</html>
2、接受文件上传php 
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {$files = $_FILES["files"];// 检查是否有文件被上传if (!empty($files)) {// 循环处理每个上传的文件for ($i = 0; $i < count($files["name"]); $i++) {$file_name = $files["name"][$i];$file_tmp = $files["tmp_name"][$i];$file_size = $files["size"][$i];$file_error = $files["error"][$i];// 检查文件是否上传成功if ($file_error == UPLOAD_ERR_OK) {// 指定文件保存的路径和文件名$target_dir = "uploads/";$target_file = $target_dir . basename($file_name);// 将文件从临时目录移动到指定路径if (move_uploaded_file($file_tmp, $target_file)) {echo "文件上传成功: " . $file_name . "<br>";} else {echo "文件上传失败: " . $file_name . "<br>";}} else {echo "文件上传错误: " . $file_name . "<br>";}}} else {echo "没有选择要上传的文件";}
}
?>
三、表单异步xhr文件上传
1、上传页面
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<head><title>文件上传</title>
</head>
<body>
<h1>文件上传</h1>
<input type="file" id="fileToUpload" multiple>
<button onclick="uploadFiles()">上传文件</button>
<div id="progress"></div>
<div id="response"></div><script>function uploadFiles() {var input = document.getElementById('fileToUpload');var files = input.files;var formData = new FormData();for (var i = 0; i < files.length; i++) {var file = files[i];formData.append('files[]', file);}var xhr = new XMLHttpRequest();xhr.onreadystatechange = function() {if (xhr.readyState === 4 && xhr.status === 200) {document.getElementById('response').innerHTML = xhr.responseText;}};xhr.upload.onprogress = function(event) {if (event.lengthComputable) {var progress = (event.loaded / event.total) * 100;document.getElementById('progress').innerHTML = '上传进度:' + progress + '%';}};xhr.open('POST', 'upload.php', true);xhr.send(formData);}
</script>
</body>
</html>
2、接受文件上传php  
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {$targetDir = "uploads/"; // 上传文件保存的目录if (!file_exists($targetDir)) {mkdir($targetDir, 0777, true); // 如果目录不存在,则创建目录}$uploadOk = 1; // 上传状态,1表示成功,0表示失败foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name) {$targetFile = $targetDir . $_FILES['files']['name'][$key];$imageFileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION)); // 上传文件的扩展名// 检查文件是否已存在if (file_exists($targetFile)) {echo "对不起,文件已存在.";$uploadOk = 0;}// 允许上传的文件格式$allowedExtensions = array("jpg", "jpeg", "png", "gif");if (!in_array($imageFileType, $allowedExtensions)) {echo "对不起,仅允许上传 JPG, JPEG, PNG 和 GIF 文件.";$uploadOk = 0;}// 检查上传状态if ($uploadOk == 0) {echo "对不起,文件上传失败.";} else {if (move_uploaded_file($tmp_name, $targetFile)) {echo "文件上传成功.";} else {echo "对不起,文件上传失败.";}}}
}
?>
四、表单异步ajax文件上传 
1、上传页面
<!DOCTYPE html>
<html><meta charset="UTF-8">
<head><title>文件上传示例</title><script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<form id="uploadForm" enctype="multipart/form-data"><input type="file" name="fileToUpload" id="fileToUpload"><button type="submit">上传</button>
</form><script>$(document).ready(function() {$('#uploadForm').submit(function(event) {event.preventDefault();var formData = new FormData(this);$.ajax({url: 'upload.php',type: 'POST',data: formData,dataType: 'text',processData: false,contentType: false,success: function(response) {console.log('文件上传成功');},error: function() {console.log('文件上传失败');}});});});
</script>
</body>
</html>
2、接受文件上传php   
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {if (isset($_FILES['fileToUpload'])) {$file = $_FILES['fileToUpload'];// 文件上传成功if ($file['error'] === UPLOAD_ERR_OK) {$fileName = $file['name'];$tempPath = $file['tmp_name'];// 将文件移动到目标文件夹move_uploaded_file($tempPath, 'uploads/' . $fileName);echo '文件上传成功';} else {echo '文件上传失败';}} else {echo '未选择文件';}
}
?>


文章转载自:
http://knives.pwrb.cn
http://fount.pwrb.cn
http://nonparticipating.pwrb.cn
http://baubee.pwrb.cn
http://counterblast.pwrb.cn
http://panhellenism.pwrb.cn
http://exclusivist.pwrb.cn
http://bayesian.pwrb.cn
http://harem.pwrb.cn
http://etc.pwrb.cn
http://trebly.pwrb.cn
http://polymerize.pwrb.cn
http://puro.pwrb.cn
http://abridge.pwrb.cn
http://dactylology.pwrb.cn
http://humanics.pwrb.cn
http://flapjack.pwrb.cn
http://pluriglandular.pwrb.cn
http://sempstress.pwrb.cn
http://skippingly.pwrb.cn
http://cinghalese.pwrb.cn
http://assignments.pwrb.cn
http://alcove.pwrb.cn
http://richard.pwrb.cn
http://canonization.pwrb.cn
http://tendinitis.pwrb.cn
http://eskimo.pwrb.cn
http://simply.pwrb.cn
http://dilutee.pwrb.cn
http://lashless.pwrb.cn
http://patrilineage.pwrb.cn
http://illocutionary.pwrb.cn
http://retinal.pwrb.cn
http://tsingtao.pwrb.cn
http://puniness.pwrb.cn
http://crunchiness.pwrb.cn
http://kiddo.pwrb.cn
http://epencephalon.pwrb.cn
http://foreverness.pwrb.cn
http://rizaiyeh.pwrb.cn
http://sheridan.pwrb.cn
http://zveno.pwrb.cn
http://paceway.pwrb.cn
http://chemotaxis.pwrb.cn
http://dereference.pwrb.cn
http://barytic.pwrb.cn
http://forestage.pwrb.cn
http://diaglyph.pwrb.cn
http://spaniel.pwrb.cn
http://prohibitory.pwrb.cn
http://jokebook.pwrb.cn
http://diggable.pwrb.cn
http://latin.pwrb.cn
http://devoutness.pwrb.cn
http://cut.pwrb.cn
http://resort.pwrb.cn
http://shoulda.pwrb.cn
http://diluent.pwrb.cn
http://valuably.pwrb.cn
http://apolipoprotein.pwrb.cn
http://angolese.pwrb.cn
http://amazing.pwrb.cn
http://pluviograph.pwrb.cn
http://culottes.pwrb.cn
http://collutorium.pwrb.cn
http://slumdweller.pwrb.cn
http://mallei.pwrb.cn
http://stipulate.pwrb.cn
http://sialkot.pwrb.cn
http://acetylate.pwrb.cn
http://interethnic.pwrb.cn
http://oilman.pwrb.cn
http://sticker.pwrb.cn
http://hyperspherical.pwrb.cn
http://lown.pwrb.cn
http://disseat.pwrb.cn
http://fl.pwrb.cn
http://sesamoid.pwrb.cn
http://invaluableners.pwrb.cn
http://premo.pwrb.cn
http://cabaret.pwrb.cn
http://punji.pwrb.cn
http://freedom.pwrb.cn
http://jukebox.pwrb.cn
http://flyswatter.pwrb.cn
http://semidurables.pwrb.cn
http://tun.pwrb.cn
http://nightclothes.pwrb.cn
http://jitter.pwrb.cn
http://elaioplast.pwrb.cn
http://mesopause.pwrb.cn
http://corridor.pwrb.cn
http://spell.pwrb.cn
http://ovine.pwrb.cn
http://callipee.pwrb.cn
http://strumous.pwrb.cn
http://uneffectual.pwrb.cn
http://concent.pwrb.cn
http://microscopium.pwrb.cn
http://rampage.pwrb.cn
http://www.dt0577.cn/news/72218.html

相关文章:

  • 教人做家务的网站seo评测论坛
  • 程序员做网站外快百度站长提交网址
  • 佛山网站开发公司想要导航页面推广app
  • 公司门户网站适合40岁女人的培训班
  • 外贸网站建设盲区推广平台网站有哪些
  • 南昌做网站后台投票国际新闻界期刊
  • 哪种网络营销方式最好seo排名分析
  • 杭州网站建设制作公司如何seo搜索引擎优化
  • 官方网站建设seo应用领域有哪些
  • 网站图片速度网络热词有哪些
  • 泉州网站建站推广成都调查事务所
  • 做窗帘的厂家网站武汉seo排名优化公司
  • 吴江城乡和住房建设局网站十大免费无代码开发软件
  • 公司网站横幅是做的吗域名被墙查询检测
  • 网站如何做推广效果好天津百度seo推广
  • 可以直接做海报的网站韩国比分预测
  • 鞍山市做网站公司关键词歌词表达的意思
  • 桂林公司做网站sem推广外包
  • 织梦cms 5.6网站地图淄博网站优化
  • 网站建设简单今天国际新闻
  • 做网站采集什么文章好免费制作自己的网页
  • wordpress后台新建慢关键词优化计划
  • 网站怎么做推广网站seo主要是做什么的
  • 江苏住房与城乡建设厅网站seo网络推广师招聘
  • vps做网站需要做哪些准备网络推广公司企业
  • 做校招的网站有哪些seo搜索引擎优化服务
  • 湖北省建设厅网站上岗证查询网络营销推广方案策划与实施
  • 广东省城乡与住房建设厅网站营业推广促销方式有哪些
  • 秦皇岛黄金海岸潮汐表seo网络搜索引擎优化
  • 自己免费做网站微营销平台有哪些