简体   繁体   English

如何使用htaccess和php从wp-content / uploads文件夹中为wordpress图像加水印?

[英]How to watermark wordpress images from wp-content/uploads folder with htaccess and php?

I have a Wordpress website, due to some limits i need to have originals of the photo at the serverside, but watermarked ones on a frontend and with direct opening of the photos. 我有一个Wordpress网站,由于某些限制,我需要在服务器端拥有照片的原件,但要在前端添加水印并直接打开照片。 I'm using Frontend content creation plugin and (as i understand) not all the plugins will fork with custom file input fields (wp_handle_upload used). 我使用的是Frontend内容创建插件,并且(据我了解),并非所有插件都将带有自定义文件输入字段(使用了wp_handle_upload)。 I've found good solution: php file + htaccess setting with RewriteRule. 我找到了很好的解决方案:php文件+带有RewriteRule的htaccess设置。 The problem is that it isn't work for me for some reason. 问题是由于某种原因它对我不起作用。

The solution is: http://dolcepixel.com/how-to-watermark-all-your-uploaded-images/ 解决方案是: http : //dolcepixel.com/how-to-watermark-all-your-uploaded-images/

When i opening file with: 当我打开文件时:

/watermark.php?p=br&q=90&src=wp-content/uploads/link/to/file.jpg /watermark.php?p=br&q=90&src=wp-content/uploads/link/to/file.jpg

everything is good, watermark is on the image, but when this image loads on the page or direct link in the browser - nothing happens. 一切都很好,图像上有水印,但是当该图像加载到页面或浏览器中的直接链接上时,什么也没有发生。 It loads original image without watermaks. 它将加载原始图像,而不会出现水渍。

There is two main settings: htaccess rule 有两个主要设置:htaccess规则

RewriteRule ^wp-content/uploads/(.*\.(jpe?g|gif|png))$ watermark.php?p=br&q=90&src=wp-content/uploads/$1

And full block of mod_rewrite section: 以及mod_rewrite部分的完整块:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^wp-content/uploads/(.*\.(jpe?g|gif|png))$ watermark.php?p=br&q=90&src=wp-content/uploads/$1
</IfModule>

the php file is bigger and it's works as i see, the problem is in something else, but you can find the .php at the link on top of the post. php文件更大,并且如我所见,它的工作原理是其他问题,但是您可以在文章顶部的链接中找到.php。

Whats the problem with me, or Apache, .htaccess or with Wordpress? 我或Apache,.htaccess或Wordpress有什么问题? If there is a way to deny any access to /uploads/ with possibility to open images throught php proxy – it is a solution also, but when i'm trying to use /wp-content/uploads/.htaccess with "deny from all" it wont work and the direct file is opens without any problems with browser. 如果有一种方法可以拒绝对/ uploads /的任何访问,并有可能通过php代理打开图像–这也是一种解决方案,但是当我尝试将/wp-content/uploads/.htaccess与“拒绝所有“它将无法正常工作,直接文件打开后浏览器不会出现任何问题。

Recently i have same problem and in my case answer vas very easy - Cashing. 最近我有同样的问题,在我的情况下,回答很容易-兑现。 So try to clear cache when you make some changes, even in .htaccess, or use another browser. 因此,当您进行了一些更改(即使在.htaccess中)或尝试使用其他浏览器时,请尝试清除缓存。 Hope it helps 希望能帮助到你

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WordPress 网站上的图片没有显示,我只在 wp-content/uploads/ 文件夹中收到图片的 404 错误 - images on WordPress site are not showing up and I'm getting 404 errors for pictures only in wp-content/uploads/ folder 如何从url隐藏/删除wp-content / uploads? - How to hide/remove wp-content/uploads from url? WordPress:wp-content文件夹与其他文件夹分开 - Wordpress: wp-content folder separated from the rest Nginx - wordpress fpm - 在 wp-content/uploads 中存储的图像上获取 404(到 EFS 的符号链接) - Nginx - wordpress fpm - getting 404 on images stored in wp-content/uploads (symbolic link to EFS) 从wp-content .htaccess中排除特定的php文件 - Exclude a specific php file from wp-content .htaccess WordPress不会在wp-content / uploads下创建图像目录 - Wordpress doesn't create the directory for images under wp-content/uploads 阿帕奇。 如何将 wp-config.php 和 wp-content 从 wordpress 核心移出? - Apache. How to move wp-config.php and wp-content outside from wordpress core? Wordpress上传的文件无法移动到wp-content / uploads - Wordpress The uploaded file could not be moved to wp-content/uploads Wordpress 错误:“上传的文件无法移动到 wp-content/uploads” - Wordpress error: 'The uploaded file could not be moved to wp-content/uploads' 媒体文件上载到/ wp-content而不是在子目录中安装的WordPress实例中的/ wp / wp-content - Media file uploads go to /wp-content instead of /wp/wp-content in a subdirectory-installed instance of WordPress
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM