


PHP image upload and watermark (automatically add watermark)/*This is a perfect PHP file upload code. After the image is uploaded successfully, it will automatically add a watermark to the image. This is very good and fast. You have to add it one by one manually. watermark effect.
php tutorial picture upload and watermark (automatically add watermark)
/*
This is a perfect php file upload code. After the picture is uploaded successfully, it will automatically add a watermark to the picture, which is very fast and fast. To improve, you have to manually add the watermark effect one by one.
*/
function upload($uploadfile,$watermark=1,$watertype=1,$content){
case 2:
foreach($uploadfile['name'] as $key=>$name) { // Multi-file upload function
uploadall($uploadfile,$key,$watermark,$watertype,$content);
}
}
function uploadall($uploadfile,$i,$watermark,$watertype ,$content) {
$watermark=$watermark; //Whether to attach a watermark (1 is watermark, others are not watermarked);
$watertype=$watertype; //Watermark type (1 is text, 2 is the picture)
$watercontent=$content; //The content of the watermark
if(empty($uploadfile['name'][$i])) {
die("No file uploaded" );
}
if($uploadfile['error'][$i] == 2) { //Verify the html judgment result
die("The uploaded file is too large");
}
$allow_filemaxsize = 2048000; // 2m
$filesize = $uploadfile['size'][$i];
if($filesize > $allow_filemaxsize) {
die(" The uploaded file is too large");
}
$allow_filetypes = array("jpeg", "gif", "png","jpg","pjpeg");//Unified resources for files allowed to be uploaded Type mimetype
$allow = false; $t) {
if(strpos($mimetype, $t) !== false) {
$allow = true; //File type that meets the upload conditions was found
break;
}
}
if($allow == false) {
die("The uploaded file type is not allowed");
}
$result = is_uploaded_file($uploadfile['tmp_name' ][$i]); //Determine whether it is generated by the upload action
if(!$result) {
die("The uploaded file is incorrect");
}
$uploaddir = "img/"; //Upload file saving directory
if(!file_exists($uploaddir)) mkdir($uploaddir, 0777, true);//If the upload saving directory does not exist, create it recursively
/* *Rename file**/
$filetype = explode(".", $uploadfile['name'][$i]);
$filetype = array_pop($filetype);
$uploadfilename = time ().".".$filetype;
$_session['filename'] = $uploadfilename;
//end
$result = move_uploaded_file($uploadfile['tmp_name'][$i], $uploaddir.$uploadfilename);
if($result) {
echo "File uploaded successfully";
}else{
switch($uploadfile['error'][$i]) {
case 1:return "The uploaded file exceeds the maximum value set in php.ini";break;
case 2:return "The uploaded file exceeds the maximum value set in html";break;
case 3:return "Only part of the file was uploaded";break;
case 4;return "No file was uploaded";break;
default:die("File upload failed");
}
}
if($watermark==1) {
$iinfo=getimagesize($uploaddir.$uploadfilename); //Get the relevant information of the image and get the array
$nimage=imagecreatetruecolor( $iinfo[0],$iinfo[1]);
$white=imagecolorallocate($nimage,255,255,255); //Set the background color to white
$black=imagecolorallocate($nimage,0,0,0 ); //Set the background color to black
$red=imagecolorallocate($nimage,255,0,0); //Set the background color to red
imagefill($nimage,0,0,$white); //The background is filled with white
switch ($iinfo[2]) {
case 1:
$simage =imagecreatefromgif($uploaddir.$uploadfilename);
break;
case 2:
$simage =imagecreatefromjpeg($uploaddir.$uploadfilename);
break;
case 3:
$simage =imagecreatefrompng($uploaddir.$uploadfilename);
break;
case 6:
$simage =imagecreatefromwbmp($uploaddir.$uploadfilename);
break;
default:
die("Unsupported file type");
exit;
}
imagecopy($nimage,$simage,0,0,0,0,$iinfo['0'],$iinfo['1']);
switch($watertype) {
case 1: // Watermark string
imagestring($nimage,5,$iinfo['0']/2-50,$iinfo['1']-30,$watercontent,$black ; $simage1,$iinfo['0']/2+50,$iinfo['1']-100,0,0,$size[0],$size[1]);
imagedestroy($simage1) ;
break;
}
switch ($iinfo[2]) {
case 1:
imagejpeg($nimage, $uploaddir.$uploadfilename); //Change the image $nimage creates a jpeg format file with the $destination file name
break;imagejpeg($nimage, $uploaddir.$uploadfilename);
break;
case 3:
imagepng($nimage, $uploaddir.$uploadfilename);
break;
case 6:
imagewbmp($nimage, $uploaddir.$uploadfilename);
break;
}
imagedestroy($nimage); //Overwrite the original uploaded file
imagedestroy($simage);
}
}
if(@$_get['act'] == "insert" ) { //No parameter verification is done
//The four parameters of this function are: the name value of the upload control; whether to add a watermark (1 is plus, other numbers are bad);
//Watermark Type (1 is a string, 2 is a picture); the content of the watermark, write the data when it is a string, and write the address of the picture when it is a picture;
$picture = upload($_files['picture'],1,2, "img/watermark.gif");//Upload the file and return the uploaded file path name
}
?>Upload code
Product picture: |
|
http://www.bkjia.com/PHPjc/444863.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/444863.html

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software