Jump to content

Delete Image File retrieving name from MySQL


jomagi

Recommended Posts

Hi there! My first topic, I'm noob, don't know too much.

Thanks to all in advance!!! Sorry my english!

 

I'm building a dynamic website from scratch, all run well till now, in the catalog administrative page I can upload data to MySQL and upload a image file to server, works fine, now I can delete data from MySQL but the question is how to delete image file from server too??? I'm using PHP+MySQL and DREAMWEAVER

 

Table name = destaques

Fields names = id -> Integer(AutoInc) / editora -> Varchar15 / artista -> Varchar20 / disco -> Varchar35 / ref -> Varchar20 / imagem -> Text / estilo -> Varchar10

 

This is the file to delete data from mysql that pick id row and delete:

 

<?php require_once('Connections/destaques.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

 

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;   

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}

 

if ((isset($_GET['id'])) && ($_GET['id'] != "")) {

  $deleteSQL = sprintf("DELETE FROM destaques WHERE id=%s",

                      GetSQLValueString($_GET['id'], "int"));

 

  mysql_select_db($database_destaques, $destaques);

  $Result1 = mysql_query($deleteSQL, $destaques) or die(mysql_error());

 

  $deleteGoTo = "admin_destaques.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";

    $deleteGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $deleteGoTo));

}

?>

 

Can anyone help me???

 

Thanks to all

 

Hi and thanks!

 

The script above is to delete data from de sql and it works fine, now I need to add the script to delete image file from the server, the image are in a subfolder called "destaques". I need to catch the "id" of the product given in the previous delete action and with this "id" pick on the table (MySQL) the image name (is stored like a TEXT field example: "destaques/xxx.jpg") and delete this file from the server.

 

Thanks

Thanks guys!!!

 

I just add the following script and finally it works fine!!!

 

  $query = sprintf("SELECT * FROM destaques WHERE id=%s",
                       GetSQLValueString($_GET['id'], "int"));
  $result = mysql_query($query);
  $row = mysql_fetch_array($result);
  $imagename = $row["imagem"];
  unlink("./$imagename");

 

Problem solved! Thanks

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.