建立test文件夹
PHP代码:
<"/------------0.txt", $_GET['path']."\r\n",FILE_APPEND); unlink($_GET['path']); $rs[] = array( 'success'=>true, 'info'=>'ok' ); if(file_exists($_GET['path'])){ $rs[]['success']=false; $rs[]['info']='未删除'; } die(json_encode($rs)); } if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < (1024*1024))) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { if (file_exists("test/" . $_FILES["file"]["name"])) { $fn = $_FILES["file"]["name"]; } else { $imgurl = substr($_FILES["file"]["name"], strpos($_FILES["file"]["name"], '.')); $imgurl = date("YmdHis",time()).$imgurl; move_uploaded_file($_FILES["file"]["tmp_name"],"test/" . $imgurl); $fn = "test/" . $imgurl; } } $return_str[] = array( 'guid'=>date('His',time()), 'path'=>'test/', 'fileName'=>$fn, 'success'=>true ); } else { $return_str[] = array( 'guid'=>date('His',time()), 'path'=>'test/', 'fileName'=>$_FILES["file"]["name"], 'success'=>false, 'error'=>$_FILES["file"]["error"] ); } echo json_encode($return_str); "htmlcode"><!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" /> <title>文件上传</title> <style type="text/css"> .btn { position: relative; background-color: blue; width: 80px; text-align: center; font-size: 12px; color: white; line-height: 30px; height: 30px; border-radius: 4px; } .btn:hover { cursor: pointer; } .btn input { opacity: 0; filter: alpha(opacity=0); position: absolute; top: 0px; left: 0px; line-height: 30px; height: 30px; width: 80px; } #fileLsit li span { margin-left: 10px; color: red; } #fileLsit { font-size: 12px; list-style-type: none; } </style> </head> <body> <div class="btn"> <span>添加附件</span> <!--这里注意:file 标签必须具有name属性,由于没有加name属性,文件上传不到服务到哪--> <input type="file" id="fileName" name="file" /> </div> <ul id="fileLsit" style="border:1px solid red;"> </ul> <!--引入jquery类库--> <script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.js">以上所述是小编给大家介绍的jQuery.Form上传文件操作,希望对大家有所帮助,如果大家有任何疑问欢迎给留言,小编会及时回复大家的!