-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathiframe_uploade.php
More file actions
executable file
·63 lines (62 loc) · 1.9 KB
/
Copy pathiframe_uploade.php
File metadata and controls
executable file
·63 lines (62 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
//处理图片上传
if($_FILES['file']['error'] > 0){
echo '!problem:';
switch($_FILES['file']['error'])
{
case 1: echo '文件大小超过php.ini中upload_max_filesize限制的值';
break;
case 2: echo '上传文件的大小超过了HTML表单中MAX_FILE_SIZE选项指定的值';
break;
case 3: echo '文件只有部分被上传';
break;
case 4: echo '文件加载失败,没有文件被上传!';
break;
}
exit;
}
if($_FILES['file']['size'] > 2*1024*1024){ //文件大小限制2M
echo '文件过大!';
exit;
}
if($_FILES['file']['type']!='image/jpeg' && $_FILES['file']['type']!='image/png'){
echo '文件不是JPG或者PNG图片!';
exit;
}
$today = date("YmdHis");
$filetype = $_FILES['file']['type']; //文件类型
if($filetype == 'image/jpeg'){
$type = '.jpg';
}
if($filetype == 'image/png'){
$type = '.png';
}
$upfilePath = '/img/img_group/' . $today . $type; //文件上传路径
if(is_uploaded_file($_FILES['file']['tmp_name'])) //文件上传
{
if(!move_uploaded_file($_FILES['file']['tmp_name'], $upfilePath))
{
echo '移动文件失败!';
exit;
}
}
else
{
echo 'problem!';
exit;
}
//页面上图片输出路径
$path = 'http://img.ljlj.loc/img_group/'.$today . $type;
?>
<!-- 这是iframe的内连框架,主要目的是把上传完的图片路径输出,html接收到这个路径,获取到不跳页面立即显示 -->
<!DOCTYPE html>
<html>
<head>
<meta name ="viewport" content= "initial-scale=1.0, user-scalable=no" >
<meta http-equiv ="Content-type" content= "text/html;charset:utf-8" >
<script type ="text/javascript" src= "jquery-1.7.2.min.js"></script>
</head>
<body >
<div id= "pic" style = "diplay:none;" ><?php echo $path; ?></div>
</body>
</html>