例如我新闻里有4条图片链接 <img src="http://www.abc.com/upimages/33333.jpg" /><img src="http://www.abc.com/upimages/555555.GIF" />
<img src="http://www.abc.com/upimages/66666.png" /><img src="http://www.abc.com/upimages/77777.bmp" />
请教高手正规表达式该如何写,还有获取图片名后进行删除的代码.谢谢!!!!
33 个解决方案
#1
just like this...
$news_content = '<img src="http://www.abc.com/upimages/33333.jpg" /> <img src="http://www.abc.com/upimages/555555.GIF" />
<img src="http://www.abc.com/upimages/66666.png" /> <img src="http://www.abc.com/upimages/77777.bmp" />';
if( preg_match_all("/<img src=\"http:\/\/www\.abc\.com\/upimages\/([\w\.]*?)\"\s?\/>/", $news_content, $getvalues) ){
foreach($getvalues[1] as $filename){
unlink('upimages/' . $filename);
}
}
#2
先谢谢hcann朋友!我把你的代码整合到DEL.PHP页面,在删除时出现了错误提示..
数据库里的图片地址是<img src="/upimages/1237822819585255660.jpg" />
我的DEL.PHP页面
删除时错误提示: Parse error: syntax error, unexpected ')' in H:\BOKA\Website\localhost\baina\admin_baina\del.php on line 14
请教高手该如何修改 谢谢了!
数据库里的图片地址是<img src="/upimages/1237822819585255660.jpg" />
我的DEL.PHP页面
<?php
include('include/config.inc');
$Nid = $_POST['Nid'];
if (empty($Nid)) {
echo("<script type='text/javascript'> alert('请选择删除对象!');location.href='news_list.php';</script>");
}
else{
$id = implode(",",$Nid);
$news_tb = mysql_query("SELECT * FROM news where ID='$id' ");
$news_rs = mysql_fetch_object($news_tb);
preg_match_all("/<img src=\"upimages\/([\w\.]*?)\"\s?\/>/",$news_rs->content, $getvalues) )
foreach($getvalues[1] as $filename){
unlink('upimages/' . $filename);
}
$sql = "delete from news where ID in(".$id.")";
$result=mysql_query($sql);
//echo $result?"删除成功":"删除失败";
echo("<script type='text/javascript'> alert('删除成功!');location.href='news_list.php';</script>");
}
?>
删除时错误提示: Parse error: syntax error, unexpected ')' in H:\BOKA\Website\localhost\baina\admin_baina\del.php on line 14
请教高手该如何修改 谢谢了!
#3
去掉14行$getvalues) 后面的括号 , 现在错误提示是
Parse error: syntax error, unexpected T_FOREACH in H:\BOKA\Website\localhost\baina\admin_baina\del.php on line 15
#4
$news_rs->content的内容是什么? 正则没匹配到值吧。
#5
<?php
include('include/config.inc');
$Nid = $_POST['Nid'];
if (empty($Nid)) {
echo("<script type='text/javascript'> alert('请选择删除对象!');location.href='news_list.php';</script>");
}
else{
$id = implode(",",$Nid);
$news_tb = mysql_query("SELECT * FROM news where ID='$id' ");
$news_rs = mysql_fetch_object($news_tb);
if (preg_match_all("/<img src=\"upimages\/([\w\.]*?)\"\s?\/>/","$news_rs->content", $getvalues) ){
foreach($getvalues[1] as $filename){
unlink('upimages/' . $filename);
}
}
$sql = "delete from news where ID in(".$id.")";
$result=mysql_query($sql);
//echo $result?"删除成功":"删除失败";
echo("<script type='text/javascript'> alert('删除成功!');location.href='news_list.php';</script>");
}
?>
现在没错误提示 可以删除数据库的数据 但图片文件没删除 哎~~ 麻烦各位帮忙看下 谢谢
#6
$news_rs->content的内容是:
<p>新闻发布页面新闻发布页面新闻发布页面新闻发布页面新闻发布页面<img height="693" width="1027" alt="" src="/upimages/1237822819585255660.jpg" /></p>
<p>新闻发布页面新闻发布页面新闻发布页面新闻发布页面新闻发布页面<img height="693" width="1027" alt="" src="/upimages/1237822819585255660.jpg" /></p>
#7
preg_match_all("/<img src=\"\/upimages\/([\w\.]*?)\"\s?\/>/","$news_rs->content", $getvalues)
把正则换一下.
把正则换一下.
#8
$id = implode(",",$Nid);
$news_tb = mysql_query("SELECT * FROM news where ID = '$id' ");
$news_rs = mysql_fetch_object($news_tb);
echo "$news_rs->content";
exit;
我选5条新闻, 以上代码输出时只显示第一条新闻的内容, 哪个地方写的不对呢?
#9
选5条新闻? echo sql语句 看看是什么 .
上面那条语句的正则:
上面那条语句的正则:
preg_match_all("/<img height=\"\d+\"\s+width=\"\d+\"\s+alt=\"[\w\s]*\"\s+src=\"\/upimages\/([\w\.]*?)\"\s?\/>/", $news_content, $getvalues)
#10
<?php
include('include/config.inc');
$Nid = $_POST['Nid'];
if (empty($Nid)) {
echo("<script type='text/javascript'> alert('请选择删除对象!');location.href='news_list.php';</script>");
}
else{
$id = implode(",",$Nid);
$news_tb = mysql_query("SELECT * FROM news where ID = '$id' ");
$news_rs = mysql_fetch_object($news_tb);
if (preg_match_all("/ <img src=\"\/upimages\/([\w\.]*?)\"\s?\/>/","$news_rs->content", $getvalues)){
foreach($getvalues[1] as $filename){
unlink('upimages/' . $filename);
}
}
$sql = "delete from news where ID in(".$id.")";
$result=mysql_query($sql);
//echo $result?"删除成功":"删除失败";
echo("<script type='text/javascript'> alert('删除成功!');location.href='news_list.php';</script>");
}
?>
目前我这段代码有2个问题:
一、删除多条新闻时,$news_rs->content只读出到第一条新闻内容,后面的新闻没读取到!
二、图片还是无法删除,程序好象绕过了 if (preg_match_all("/ <img src=\"\/upimages\/([\w\.]*?)\"\s?\/>/","$news_rs->content", $getvalues)){
foreach($getvalues[1] as $filename){
unlink('upimages/' . $filename);
}
}这段代码,直接执行
$sql = "delete from news where ID in(".$id.")";
$result=mysql_query($sql);
所以删除新闻时只删除了数据库的数据 而图片文件没删除。
请各位高手再帮忙看看 这页面花了我2天时间还没搞掂 哎。。。
#11
$news_tb = mysql_query("SELECT * FROM news where ID = '$id' ");
$news_rs = mysql_fetch_object($news_tb);
print ("$news_tb");
exit;
输出 Resource id #4
#12
echo "SELECT * FROM news where ID = '$id' ";
如果你的$id包含多个值的话, 不应该这么写。
如果你的$id包含多个值的话, 不应该这么写。
#13
$id 的确包含多个值
多个值的查询语句该怎么写呢 请指教..
多个值的查询语句该怎么写呢 请指教..
#14
改写成
现在错误提示是 Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in H:\BOKA\Website\localhost\baina\admin_baina\del.php on line 13
$news_tb = mysql_query("SELECT * FROM news where in ( '$id') ");
$news_rs = mysql_fetch_object($news_tb);
echo "$news_rs->content";
exit;
现在错误提示是 Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in H:\BOKA\Website\localhost\baina\admin_baina\del.php on line 13
#15
执行下面这段查询语句 输出了错误提示
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN ( '33,32,31,30,29,28,27,26,25')' at line 1
$news_tb = mysql_query("SELECT * FROM news where IN ( '$id') ");
echo "$news_tb".mysql_error();
exit;
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN ( '33,32,31,30,29,28,27,26,25')' at line 1
#16
试试这样:
$news_tb = mysql_query("SELECT * FROM news where ID IN ( $id ) ");
echo "SELECT * FROM news where ID IN ( $id ) ";
exit;
$news_tb = mysql_query("SELECT * FROM news where ID IN ( $id ) ");
echo "SELECT * FROM news where ID IN ( $id ) ";
exit;
#17
这句没问题 输出显示 SELECT * FROM news where ID IN ( 33,32,31,30,29,28,27,26,25 )
但后面$news_rs->content输出时只输出第一条新闻内容
$news_tb = mysql_query("SELECT * FROM news where ID in ( $id) ");
$news_rs = mysql_fetch_object($news_tb);
echo "$news_rs->content";
exit;
#18
这句
$news_rs = mysql_fetch_object($news_tb); 是不是要修改?
#19
改成这样
$news_tb = mysql_query("SELECT * FROM news where ID IN ( $id ) ");
while ($news_rs = mysql_fetch_object($news_tb)) {
echo $news_rs->content;
}
#20
OK 所有新闻内容出来了
最后一步怎么把这些内容集合到一个变量中,在正则表达式里筛选出图片文件名呢?
#21
$news_tb = mysql_query("SELECT * FROM news where ID IN ( $id ) ");
$news_contents = "";
while ($news_rs = mysql_fetch_object($news_tb)) {
$news_contents .= $news_rs->content;
}
echo $news_contents;
#22
现在$news_contents的内容是
<p>安全性测试安全性测试安全性测试安全性测试</p>
<p><del><span style="font-family: Comic Sans MS"><span style="font-size: large">dgfdgdfgfdgdfgdgd<img height="75" width="440" alt="" src="/upimages/12378824301776145431.gif" /></span></span></del></p><p><img height="75" width="440" alt="" src="/upimages/12378824121049062231.gif" /></p>
<p> gdgfgdf</p>
你给我的正则表达式好象无效 图片依然删除不了.
if (preg_match_all("/<img height=\"\d+\"\s+width=\"\d+\"\s+alt=\"[\w\s]*\"\s+src=\"\/upimages\/([\w\.]*?)\"\s?\/>/",$news_contents, $getvalues)){
foreach($getvalues[1] as $filename){
unlink('upimages/' . $filename);
}
<p>安全性测试安全性测试安全性测试安全性测试</p>
<p><del><span style="font-family: Comic Sans MS"><span style="font-size: large">dgfdgdfgfdgdfgdgd<img height="75" width="440" alt="" src="/upimages/12378824301776145431.gif" /></span></span></del></p><p><img height="75" width="440" alt="" src="/upimages/12378824121049062231.gif" /></p>
<p> gdgfgdf</p>
你给我的正则表达式好象无效 图片依然删除不了.
if (preg_match_all("/<img height=\"\d+\"\s+width=\"\d+\"\s+alt=\"[\w\s]*\"\s+src=\"\/upimages\/([\w\.]*?)\"\s?\/>/",$news_contents, $getvalues)){
foreach($getvalues[1] as $filename){
unlink('upimages/' . $filename);
}
#23
你copy的多了一个空格,这个代码我测试过了,你再复制一下。
if (preg_match_all("/<img height=\"\d+\"\s+width=\"\d+\"\s+alt=\"[\w\s]*\"\s+src=\"\/upimages\/([\w\.]*?)\"\s?\/>/",$news_contents, $getvalues)){
foreach($getvalues[1] as $filename){
unlink('upimages/' . $filename);
}
}
#24
删除时出现错误提示
Warning: unlink(upimages/12378840421531236925.gif) [function.unlink]: No such file or directory in H:\BOKA\Website\localhost\baina\admin_baina\del.php on line 20
Warning: unlink(upimages/12378840421531236925.gif) [function.unlink]: No such file or directory in H:\BOKA\Website\localhost\baina\admin_baina\del.php on line 20
#25
你的 upimages 目录在哪儿呢?路径问题,试试 unlink('/upimages/' . $filename);
#26
成功了!! unlink('upimages/' . $filename);
这里的upimages前面要加../ 因为DEL.PHP和upimages不在同个目录下
还有个问题 如果我图片里加了其他属性 或者 width和height不写进去 不就筛选不出图片名称了吗?
<img align="center" alt="" src="/upimages/1237822819585255660.jpg" />
能否写一条只获取upimages/后面图片名的表达式呢?
这里的upimages前面要加../ 因为DEL.PHP和upimages不在同个目录下
还有个问题 如果我图片里加了其他属性 或者 width和height不写进去 不就筛选不出图片名称了吗?
<img align="center" alt="" src="/upimages/1237822819585255660.jpg" />
能否写一条只获取upimages/后面图片名的表达式呢?
#27
可以使用下面这个正则:
preg_match_all("/<img\s+[^>]*src=\"\/upimages\/([\w\.]*?)\"\s?\/>/",$news_contents, $getvalues)
#28
终于实现我要的功能了!!!!!!!!
万分感激hcann!!!!!!!!!! hcann技术牛 人也非常好 一整天不嫌烦琐的帮我解决程序中每一个错误 真的非常感激!!
感觉这50分给少了 早知就赏100分!
万分感激hcann!!!!!!!!!! hcann技术牛 人也非常好 一整天不嫌烦琐的帮我解决程序中每一个错误 真的非常感激!!
感觉这50分给少了 早知就赏100分!
#29
过讲了,过讲了,不过今天比较闲而已。
#30
我来请教一下hcann得回复
#31
感谢那么耐心的指导。谢谢。学习ing
#32
楼主。您好。我现在也碰到同样问题需要解决。。能否指点一二呢?
#33
我是用的ECSHOP 2.7.3系统 内置的也是FCKEDITOR
删除商品同时无法删除详细描述内的图片 不知道您熟悉ECSHOP么
我修改的是admin/goods.php
删除商品同时无法删除详细描述内的图片 不知道您熟悉ECSHOP么
我修改的是admin/goods.php
/* 删除商品图片和轮播图片文件 */
$sql = "SELECT goods_thumb, goods_img, original_img, goods_desc " .
"FROM " . $GLOBALS['ecs']->table('goods') .
" WHERE goods_id " . db_create_in($goods_id);
$res = $GLOBALS['db']->query($sql);
while ($goods = $GLOBALS['db']->fetchRow($res))
{
/* 删除内容中的图片 */
delete_goods_img($goods['goods_desc']);
if (!empty($goods['goods_thumb']))
{
@unlink('../' . $goods['goods_thumb']);
}
if (!empty($goods['goods_img']))
{
@unlink('../' . $goods['goods_img']);
}
if (!empty($goods['original_img']))
{
@unlink('../' . $goods['original_img']);
}
}
/**
* 删除代码中的图片
* @param mix $good_desc 删除商品介绍中的图片
* @return void
*/
function delete_goods_img($good_desc)
{
$match = "<img[^>]*?src=[\"'\s]*?([^>\"']*?)[\"'>]*?[^>]*?>";
preg_match_all("@$match@isU", $good_desc, $img);
$imgurls = array_unique($img[1]);
$siteurl = dirname($GLOBALS['admin_path']);
foreach ($imgurls as $img)
{
$img = trim($img);
if( preg_match("@^http://@is", $img) )
{
if( preg_match("@^$siteurl@is", $img) )
{
$img = preg_replace("@^$siteurl@is", '', $img);
}else{
continue;
}
}
if(is_file(ROOT_PATH .'/'. $img))
{
unlink(ROOT_PATH .'/'. $img);
}elseif(is_file('../'. $img))
{
unlink('../'. $img);
}
}
}
#1
just like this...
$news_content = '<img src="http://www.abc.com/upimages/33333.jpg" /> <img src="http://www.abc.com/upimages/555555.GIF" />
<img src="http://www.abc.com/upimages/66666.png" /> <img src="http://www.abc.com/upimages/77777.bmp" />';
if( preg_match_all("/<img src=\"http:\/\/www\.abc\.com\/upimages\/([\w\.]*?)\"\s?\/>/", $news_content, $getvalues) ){
foreach($getvalues[1] as $filename){
unlink('upimages/' . $filename);
}
}
#2
先谢谢hcann朋友!我把你的代码整合到DEL.PHP页面,在删除时出现了错误提示..
数据库里的图片地址是<img src="/upimages/1237822819585255660.jpg" />
我的DEL.PHP页面
删除时错误提示: Parse error: syntax error, unexpected ')' in H:\BOKA\Website\localhost\baina\admin_baina\del.php on line 14
请教高手该如何修改 谢谢了!
数据库里的图片地址是<img src="/upimages/1237822819585255660.jpg" />
我的DEL.PHP页面
<?php
include('include/config.inc');
$Nid = $_POST['Nid'];
if (empty($Nid)) {
echo("<script type='text/javascript'> alert('请选择删除对象!');location.href='news_list.php';</script>");
}
else{
$id = implode(",",$Nid);
$news_tb = mysql_query("SELECT * FROM news where ID='$id' ");
$news_rs = mysql_fetch_object($news_tb);
preg_match_all("/<img src=\"upimages\/([\w\.]*?)\"\s?\/>/",$news_rs->content, $getvalues) )
foreach($getvalues[1] as $filename){
unlink('upimages/' . $filename);
}
$sql = "delete from news where ID in(".$id.")";
$result=mysql_query($sql);
//echo $result?"删除成功":"删除失败";
echo("<script type='text/javascript'> alert('删除成功!');location.href='news_list.php';</script>");
}
?>
删除时错误提示: Parse error: syntax error, unexpected ')' in H:\BOKA\Website\localhost\baina\admin_baina\del.php on line 14
请教高手该如何修改 谢谢了!
#3
去掉14行$getvalues) 后面的括号 , 现在错误提示是
Parse error: syntax error, unexpected T_FOREACH in H:\BOKA\Website\localhost\baina\admin_baina\del.php on line 15
#4
$news_rs->content的内容是什么? 正则没匹配到值吧。
#5
<?php
include('include/config.inc');
$Nid = $_POST['Nid'];
if (empty($Nid)) {
echo("<script type='text/javascript'> alert('请选择删除对象!');location.href='news_list.php';</script>");
}
else{
$id = implode(",",$Nid);
$news_tb = mysql_query("SELECT * FROM news where ID='$id' ");
$news_rs = mysql_fetch_object($news_tb);
if (preg_match_all("/<img src=\"upimages\/([\w\.]*?)\"\s?\/>/","$news_rs->content", $getvalues) ){
foreach($getvalues[1] as $filename){
unlink('upimages/' . $filename);
}
}
$sql = "delete from news where ID in(".$id.")";
$result=mysql_query($sql);
//echo $result?"删除成功":"删除失败";
echo("<script type='text/javascript'> alert('删除成功!');location.href='news_list.php';</script>");
}
?>
现在没错误提示 可以删除数据库的数据 但图片文件没删除 哎~~ 麻烦各位帮忙看下 谢谢
#6
$news_rs->content的内容是:
<p>新闻发布页面新闻发布页面新闻发布页面新闻发布页面新闻发布页面<img height="693" width="1027" alt="" src="/upimages/1237822819585255660.jpg" /></p>
<p>新闻发布页面新闻发布页面新闻发布页面新闻发布页面新闻发布页面<img height="693" width="1027" alt="" src="/upimages/1237822819585255660.jpg" /></p>
#7
preg_match_all("/<img src=\"\/upimages\/([\w\.]*?)\"\s?\/>/","$news_rs->content", $getvalues)
把正则换一下.
把正则换一下.
#8
$id = implode(",",$Nid);
$news_tb = mysql_query("SELECT * FROM news where ID = '$id' ");
$news_rs = mysql_fetch_object($news_tb);
echo "$news_rs->content";
exit;
我选5条新闻, 以上代码输出时只显示第一条新闻的内容, 哪个地方写的不对呢?
#9
选5条新闻? echo sql语句 看看是什么 .
上面那条语句的正则:
上面那条语句的正则:
preg_match_all("/<img height=\"\d+\"\s+width=\"\d+\"\s+alt=\"[\w\s]*\"\s+src=\"\/upimages\/([\w\.]*?)\"\s?\/>/", $news_content, $getvalues)
#10
<?php
include('include/config.inc');
$Nid = $_POST['Nid'];
if (empty($Nid)) {
echo("<script type='text/javascript'> alert('请选择删除对象!');location.href='news_list.php';</script>");
}
else{
$id = implode(",",$Nid);
$news_tb = mysql_query("SELECT * FROM news where ID = '$id' ");
$news_rs = mysql_fetch_object($news_tb);
if (preg_match_all("/ <img src=\"\/upimages\/([\w\.]*?)\"\s?\/>/","$news_rs->content", $getvalues)){
foreach($getvalues[1] as $filename){
unlink('upimages/' . $filename);
}
}
$sql = "delete from news where ID in(".$id.")";
$result=mysql_query($sql);
//echo $result?"删除成功":"删除失败";
echo("<script type='text/javascript'> alert('删除成功!');location.href='news_list.php';</script>");
}
?>
目前我这段代码有2个问题:
一、删除多条新闻时,$news_rs->content只读出到第一条新闻内容,后面的新闻没读取到!
二、图片还是无法删除,程序好象绕过了 if (preg_match_all("/ <img src=\"\/upimages\/([\w\.]*?)\"\s?\/>/","$news_rs->content", $getvalues)){
foreach($getvalues[1] as $filename){
unlink('upimages/' . $filename);
}
}这段代码,直接执行
$sql = "delete from news where ID in(".$id.")";
$result=mysql_query($sql);
所以删除新闻时只删除了数据库的数据 而图片文件没删除。
请各位高手再帮忙看看 这页面花了我2天时间还没搞掂 哎。。。
#11
$news_tb = mysql_query("SELECT * FROM news where ID = '$id' ");
$news_rs = mysql_fetch_object($news_tb);
print ("$news_tb");
exit;
输出 Resource id #4
#12
echo "SELECT * FROM news where ID = '$id' ";
如果你的$id包含多个值的话, 不应该这么写。
如果你的$id包含多个值的话, 不应该这么写。
#13
$id 的确包含多个值
多个值的查询语句该怎么写呢 请指教..
多个值的查询语句该怎么写呢 请指教..
#14
改写成
现在错误提示是 Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in H:\BOKA\Website\localhost\baina\admin_baina\del.php on line 13
$news_tb = mysql_query("SELECT * FROM news where in ( '$id') ");
$news_rs = mysql_fetch_object($news_tb);
echo "$news_rs->content";
exit;
现在错误提示是 Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in H:\BOKA\Website\localhost\baina\admin_baina\del.php on line 13
#15
执行下面这段查询语句 输出了错误提示
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN ( '33,32,31,30,29,28,27,26,25')' at line 1
$news_tb = mysql_query("SELECT * FROM news where IN ( '$id') ");
echo "$news_tb".mysql_error();
exit;
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN ( '33,32,31,30,29,28,27,26,25')' at line 1
#16
试试这样:
$news_tb = mysql_query("SELECT * FROM news where ID IN ( $id ) ");
echo "SELECT * FROM news where ID IN ( $id ) ";
exit;
$news_tb = mysql_query("SELECT * FROM news where ID IN ( $id ) ");
echo "SELECT * FROM news where ID IN ( $id ) ";
exit;
#17
这句没问题 输出显示 SELECT * FROM news where ID IN ( 33,32,31,30,29,28,27,26,25 )
但后面$news_rs->content输出时只输出第一条新闻内容
$news_tb = mysql_query("SELECT * FROM news where ID in ( $id) ");
$news_rs = mysql_fetch_object($news_tb);
echo "$news_rs->content";
exit;
#18
这句
$news_rs = mysql_fetch_object($news_tb); 是不是要修改?
#19
改成这样
$news_tb = mysql_query("SELECT * FROM news where ID IN ( $id ) ");
while ($news_rs = mysql_fetch_object($news_tb)) {
echo $news_rs->content;
}
#20
OK 所有新闻内容出来了
最后一步怎么把这些内容集合到一个变量中,在正则表达式里筛选出图片文件名呢?
#21
$news_tb = mysql_query("SELECT * FROM news where ID IN ( $id ) ");
$news_contents = "";
while ($news_rs = mysql_fetch_object($news_tb)) {
$news_contents .= $news_rs->content;
}
echo $news_contents;
#22
现在$news_contents的内容是
<p>安全性测试安全性测试安全性测试安全性测试</p>
<p><del><span style="font-family: Comic Sans MS"><span style="font-size: large">dgfdgdfgfdgdfgdgd<img height="75" width="440" alt="" src="/upimages/12378824301776145431.gif" /></span></span></del></p><p><img height="75" width="440" alt="" src="/upimages/12378824121049062231.gif" /></p>
<p> gdgfgdf</p>
你给我的正则表达式好象无效 图片依然删除不了.
if (preg_match_all("/<img height=\"\d+\"\s+width=\"\d+\"\s+alt=\"[\w\s]*\"\s+src=\"\/upimages\/([\w\.]*?)\"\s?\/>/",$news_contents, $getvalues)){
foreach($getvalues[1] as $filename){
unlink('upimages/' . $filename);
}
<p>安全性测试安全性测试安全性测试安全性测试</p>
<p><del><span style="font-family: Comic Sans MS"><span style="font-size: large">dgfdgdfgfdgdfgdgd<img height="75" width="440" alt="" src="/upimages/12378824301776145431.gif" /></span></span></del></p><p><img height="75" width="440" alt="" src="/upimages/12378824121049062231.gif" /></p>
<p> gdgfgdf</p>
你给我的正则表达式好象无效 图片依然删除不了.
if (preg_match_all("/<img height=\"\d+\"\s+width=\"\d+\"\s+alt=\"[\w\s]*\"\s+src=\"\/upimages\/([\w\.]*?)\"\s?\/>/",$news_contents, $getvalues)){
foreach($getvalues[1] as $filename){
unlink('upimages/' . $filename);
}
#23
你copy的多了一个空格,这个代码我测试过了,你再复制一下。
if (preg_match_all("/<img height=\"\d+\"\s+width=\"\d+\"\s+alt=\"[\w\s]*\"\s+src=\"\/upimages\/([\w\.]*?)\"\s?\/>/",$news_contents, $getvalues)){
foreach($getvalues[1] as $filename){
unlink('upimages/' . $filename);
}
}
#24
删除时出现错误提示
Warning: unlink(upimages/12378840421531236925.gif) [function.unlink]: No such file or directory in H:\BOKA\Website\localhost\baina\admin_baina\del.php on line 20
Warning: unlink(upimages/12378840421531236925.gif) [function.unlink]: No such file or directory in H:\BOKA\Website\localhost\baina\admin_baina\del.php on line 20
#25
你的 upimages 目录在哪儿呢?路径问题,试试 unlink('/upimages/' . $filename);
#26
成功了!! unlink('upimages/' . $filename);
这里的upimages前面要加../ 因为DEL.PHP和upimages不在同个目录下
还有个问题 如果我图片里加了其他属性 或者 width和height不写进去 不就筛选不出图片名称了吗?
<img align="center" alt="" src="/upimages/1237822819585255660.jpg" />
能否写一条只获取upimages/后面图片名的表达式呢?
这里的upimages前面要加../ 因为DEL.PHP和upimages不在同个目录下
还有个问题 如果我图片里加了其他属性 或者 width和height不写进去 不就筛选不出图片名称了吗?
<img align="center" alt="" src="/upimages/1237822819585255660.jpg" />
能否写一条只获取upimages/后面图片名的表达式呢?
#27
可以使用下面这个正则:
preg_match_all("/<img\s+[^>]*src=\"\/upimages\/([\w\.]*?)\"\s?\/>/",$news_contents, $getvalues)
#28
终于实现我要的功能了!!!!!!!!
万分感激hcann!!!!!!!!!! hcann技术牛 人也非常好 一整天不嫌烦琐的帮我解决程序中每一个错误 真的非常感激!!
感觉这50分给少了 早知就赏100分!
万分感激hcann!!!!!!!!!! hcann技术牛 人也非常好 一整天不嫌烦琐的帮我解决程序中每一个错误 真的非常感激!!
感觉这50分给少了 早知就赏100分!
#29
过讲了,过讲了,不过今天比较闲而已。
#30
我来请教一下hcann得回复
#31
感谢那么耐心的指导。谢谢。学习ing
#32
楼主。您好。我现在也碰到同样问题需要解决。。能否指点一二呢?
#33
我是用的ECSHOP 2.7.3系统 内置的也是FCKEDITOR
删除商品同时无法删除详细描述内的图片 不知道您熟悉ECSHOP么
我修改的是admin/goods.php
删除商品同时无法删除详细描述内的图片 不知道您熟悉ECSHOP么
我修改的是admin/goods.php
/* 删除商品图片和轮播图片文件 */
$sql = "SELECT goods_thumb, goods_img, original_img, goods_desc " .
"FROM " . $GLOBALS['ecs']->table('goods') .
" WHERE goods_id " . db_create_in($goods_id);
$res = $GLOBALS['db']->query($sql);
while ($goods = $GLOBALS['db']->fetchRow($res))
{
/* 删除内容中的图片 */
delete_goods_img($goods['goods_desc']);
if (!empty($goods['goods_thumb']))
{
@unlink('../' . $goods['goods_thumb']);
}
if (!empty($goods['goods_img']))
{
@unlink('../' . $goods['goods_img']);
}
if (!empty($goods['original_img']))
{
@unlink('../' . $goods['original_img']);
}
}
/**
* 删除代码中的图片
* @param mix $good_desc 删除商品介绍中的图片
* @return void
*/
function delete_goods_img($good_desc)
{
$match = "<img[^>]*?src=[\"'\s]*?([^>\"']*?)[\"'>]*?[^>]*?>";
preg_match_all("@$match@isU", $good_desc, $img);
$imgurls = array_unique($img[1]);
$siteurl = dirname($GLOBALS['admin_path']);
foreach ($imgurls as $img)
{
$img = trim($img);
if( preg_match("@^http://@is", $img) )
{
if( preg_match("@^$siteurl@is", $img) )
{
$img = preg_replace("@^$siteurl@is", '', $img);
}else{
continue;
}
}
if(is_file(ROOT_PATH .'/'. $img))
{
unlink(ROOT_PATH .'/'. $img);
}elseif(is_file('../'. $img))
{
unlink('../'. $img);
}
}
}