<!DOCTYPE
html
>
<
html
>
<
head
>
<
title
>
测试
</
title
>
</
head
>
<
body
>
<
form
action=
"index_ok.php"
method=
"post"
enctype=
"multipart/form-data"
>
文字内容:
<
input
type=
"text"
name=
"font"
>
<
input
type=
"file"
name=
"file"
>
</
br
>
<
input
type=
"submit"
name=
"submit"
value=
"提交"
>
</
form
>
</
body
>
</html>
<?php
$file
=
$_FILES
[
"file"
];
//获取图片内容
$fontName
=
$_POST
[
'font'
];
//获取文字信息
if
(
$file
[
'size'
]>
0
&& !
empty
(
$fontName
)){
//判断空
if
(!
file_exists
(
$file
[
'name'
])){
//判断文件是否存在
// print_r($file);
$file_name
=
$file
[
'name'
];
//tmp
// echo $file_name;
if
(
move_uploaded_file
(
$file
[
'tmp_name'
],
$file
[
'name'
])){
//是否上传完
$tmp
=
true
;
}
else
{
$tmp
=
false
;
}
if
(
$tmp
){
if
(
$file
[
'type'
]==
"image/jpeg"
){
//是不是jpg格式
$img
=
imagecreatefromjpeg
(
$file_name
);
//创建图片
header
(
'Content-type: image/jpeg'
);
imagestring
(
$img
,
5
,
3
,
3
,
'by lc create'
.
$fontName
,
imagecolorallocate
(
$img
,
255
,
255
,
255
));
//加水印
imagejpeg
(
$img
);
//加载图片
}
else if
(
$file
[
'type'
]==
"image/png"
){
$img
=
imagecreatefrompng
(
$file_name
);
header
(
'Content-type: image/png'
);
imagestring
(
$img
,
5
,
3
,
3
,
'by lc create'
.
$fontName
,
imagecolorallocate
(
$img
,
255
,
255
,
255
));
imagepng
(
$img
);
}
}
}
else
{
echo
"文件存在"
;
}
}
else
{
echo
'文件空或者没文字'
;
}