如何解决上传字节的php水印问题
所以这个代码是我在网上找到的,它工作得很好......除了当我将它上传到我的网站时我并没有试图用它来给我的照片加水印,但是我的图像是原始和大 res png 格式和代码对于较大的文件没有等待期,并且在字节超时或超出时死亡 我如何添加一个像我的其他上传器一样的超时缓冲区,它可以接受 x
大小的图像或文件(以 mb 或字节为单位)?>
$targetDir = "uploads/";
$watermarkImagePath = 'abcd.png';
$statusMsg = '';
if(isset($_POST["submit"])){
if(!empty($_FILES["file"]["name"])){
// File upload path
$fileName = basename($_FILES["file"]["name"]);
$targetFilePath = $targetDir . $fileName;
$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
// Allow certain file formats
$allowTypes = array('jpg','png','jpeg');
if(in_array($fileType,$allowTypes)){
// Upload file to the server
if(move_uploaded_file($_FILES["file"]["tmp_name"],$targetFilePath)){
// Load the stamp and the photo to apply the watermark to
$watermarkImg = imagecreatefrompng($watermarkImagePath);
switch($fileType){
case 'jpg':
$im = imagecreatefromjpeg($targetFilePath);
break;
case 'jpeg':
$im = imagecreatefromjpeg($targetFilePath);
break;
case 'png':
$im = imagecreatefrompng($targetFilePath);
break;
default:
$im = imagecreatefromjpeg($targetFilePath);
}
// Set the margins for the watermark
$marge_right = 10;
$marge_bottom = 10;
// Get the height/width of the watermark image
$sx = imagesx($watermarkImg);
$sy = imagesy($watermarkImg);
// copy the watermark image onto our photo using the margin offsets and
// the photo width to calculate the positioning of the watermark.
imagecopy($im,$watermarkImg,imagesx($im) - $sx - $marge_right,imagesy($im) - $sy - $marge_bottom,imagesx($watermarkImg),imagesy($watermarkImg));
// Save image and free memory
imagepng($im,$targetFilePath);
imagedestroy($im);
if(file_exists($targetFilePath)){
$statusMsg = "The image with watermark has been uploaded successfully.";
}else{
$statusMsg = "Image upload Failed,please try again.";
}
}else{
$statusMsg = "Sorry,there was an error uploading your file.";
}
}else{
$statusMsg = 'Sorry,only JPG,JPEG,and PNG files are allowed to upload.';
}
}else{
$statusMsg = 'Please select a file to upload.';
}
}
// display status message
echo $statusMsg;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。