jquery - filter img src to remove file in directory, How to cut the array remove file in php -
i have html structure below, random div tag , img tag, , these store in database too.
have filter img src in below string, remove files not in structure store in directory,
whats best way src in structure in frontend use jquery or server side use php.
suggestion how this? much!!
in frontend
<div class="h1">content<div> <div class="h1" style="">content</div> <div class="h1" style="">...</div> <div class="h2">...</div> <div class="h1" style="">content</div> <img src="u_img/5/1.png" style="" class=""> <div class="link" style="">link: http://...</div> <img src="u_img/5/14.jpeg" style="" class=""> <div class="h1" style=""..</div> <img src="u_img/5/3.png" style="" class="">
in database
<div class="h1">content<div><div class="h1" style="">content</div><div class="h1" style="">...</div><div class="h2">...</div><div class="h1" style="">content</div><img src="u_img/5/1.png" style="" class=""><div class="link" style="">link: http://...</div><img src="u_img/5/14.jpeg" style="" class=""><div class="h1" style=""..</div><img src="u_img/5/3.png" style="" class="">
update
if img src in frontend store in array post via jquery php file below, how delete file not in array
var srcarray=$('img').map(function(){ return $(this).attr('src'); }); var fd = new formdata(uf[0]); fd.append('srcarray',srcarray); $.ajax({ type: "post", url: "img_clean.php", data: fd, processdata: false, contenttype: false, })
php
$srcarray = $_post['srcarray']; //how delete file not in array? foreach($srcarray $row){ $dir = "u_img_p/".$id; //unlink($dir.'/'.$row); } }
use attr()
src
$('img').each(function(){ var $src=$(this).attr('src'); //prop() latest versio of jquery. //do stuff ..$src source });
or can use map() store source in array
var srcarray=$('img').map(function(){ return $(this).attr('src'); //prop() latest versio of jquery. });
srcarray
have image sources.
note:$('img')
selects image tag present in document .. careful
updated after edit.
$.ajax({ type: "post", url: "img_clean.php", data: {'postedvalue':srcarray}, processdata: false, contenttype: false, })
php
$srcarray = $_post['postedvalue']; foreach($srcarray $row){ $dir = "u_img_p/".$id; unlink($dir.'/'.$row); //delete } }
Comments
Post a Comment