¿Alguna idea sobre como lo podría hacer? gracias anticipadas.
Código PHP:
$handle = fopen("csv-temp/productos.csv", "r");
if ($borrar_productos == "1") {
echo "<br/>Buscando productos que ya no existan...<br/>";
$registros_encontrados = $link->query("SELECT * FROM ps_product") or die (mysql_error());
while ($registro = mysqli_fetch_array($registros_encontrados)){
$ref = $registro['reference'];
if(!stristr($handle, $ref)){
$buscaid = $link->query("SELECT id_product FROM ps_product WHERE reference='$reference'") or die (mysql_error()); $id_product = mysqli_fetch_row($buscaid); $id = $id_product[0];
$link->query("delete from ps_product where reference = $ref");
$link->query("delete from ps_product_shop where id_product= $id");
$link->query("delete from ps_category_product where id_product= $id");
$link->query("delete from ps_product_lang where id_product= $id and id_lang=1");
$link->query("delete from ps_product_lang where id_product= $id and id_lang=2");
$link->query("delete from ps_product_lang where id_product= $id and id_lang=3");
$link->query("delete from ps_specific_price where id_product= $id");
$link->query("delete from ps_stock_available where id_product= $id");
$link->query("delete from ps_image where id_product= $id");
$link->query("delete from ps_image_shop where id_image= $id");
$link->query("delete from ps_image_lang where id_image= $id and id_lang=1");
$link->query("delete from ps_image_lang where id_image= $id and id_lang=2");
$link->query("delete from ps_image_lang where id_image= $id and id_lang=3");
$cuentaid = strlen($id);
if ($cuentaid == 1 or $cuentaid == 2 or $cuentaid == 3 or $cuentaid == 4 or $cuentaid == 5) {
$caracter1 = $id[0];
}
if ($cuentaid == 2 or $cuentaid == 3 or $cuentaid == 4 or $cuentaid == 5) {
$caracter2 = $id[1];
}
if ($cuentaid == 3 or $cuentaid == 4 or $cuentaid == 5) {
$caracter3 = $id[2];
}
if ($cuentaid == 4 or $cuentaid == 5) {
$caracter4 = $id[3];
}
if ($cuentaid == 5) {
$caracter5 = $id[4];
}
if ($cuentaid == 5) {
$dir = "../img/p/".$caracter1."/".$caracter2."/".$caracter3."/".$caracter4."/".$caracter5."/";
}
if ($cuentaid == 4) {
$dir = "../img/p/".$caracter1."/".$caracter2."/".$caracter3."/".$caracter4."/";
}
if ($cuentaid == 3) {
$dir = "../img/p/".$caracter1."/".$caracter2."/".$caracter3."/";
}
if ($cuentaid == 2) {
$dir = "../img/p/".$caracter1."/".$caracter2."/";
}
if ($cuentaid == 1) {
$dir = "../img/p/".$caracter1."/";
}
$ficheroseliminados= 0;
$handle = opendir($dir);
while ($file = readdir($handle)) {
if (is_file($dir.$file)) {
if ( unlink($dir.$file) ){
$ficheroseliminados++;
}
}
}
echo "<br/>Producto con referencia: <b> $ref </b> eliminado con éxito<br/>";
}
}
}