建立test文件夹
PHP代码:
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"] . "
";
}
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);
?>
HTML代码:
文件上传 .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; } 添加附件
以上所述是小编给大家介绍的jQuery.Form上传文件操作,希望对大家有所帮助,如果大家有任何疑问欢迎给留言,小编会及时回复大家的!



