jomagi Posted January 22, 2009 Share Posted January 22, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/141975-delete-image-file-retrieving-name-from-mysql/ Share on other sites More sharing options...
Philip Posted January 22, 2009 Share Posted January 22, 2009 If you're wanting to delete the actual file, take a look at unlink() Quote Link to comment https://forums.phpfreaks.com/topic/141975-delete-image-file-retrieving-name-from-mysql/#findComment-743408 Share on other sites More sharing options...
jomagi Posted January 22, 2009 Author Share Posted January 22, 2009 Yes, searching internet I find unlink() to be the right way, but can't make the correct add to my script to do the action. Can help me??? Thks Quote Link to comment https://forums.phpfreaks.com/topic/141975-delete-image-file-retrieving-name-from-mysql/#findComment-743418 Share on other sites More sharing options...
jomagi Posted January 23, 2009 Author Share Posted January 23, 2009 Can anyone help me with the code? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/141975-delete-image-file-retrieving-name-from-mysql/#findComment-744126 Share on other sites More sharing options...
jomagi Posted January 25, 2009 Author Share Posted January 25, 2009 Nobody can help me? Thks Quote Link to comment https://forums.phpfreaks.com/topic/141975-delete-image-file-retrieving-name-from-mysql/#findComment-745815 Share on other sites More sharing options...
landavia Posted January 25, 2009 Share Posted January 25, 2009 hmm.. i can't see this script gone into well.. we might help. 1. where you put your image 2. what condition you delete ur image if i'm not mistaken.. nothing in your script contain about image, upload image or sort of Quote Link to comment https://forums.phpfreaks.com/topic/141975-delete-image-file-retrieving-name-from-mysql/#findComment-745862 Share on other sites More sharing options...
jomagi Posted January 25, 2009 Author Share Posted January 25, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/141975-delete-image-file-retrieving-name-from-mysql/#findComment-746070 Share on other sites More sharing options...
jomagi Posted January 28, 2009 Author Share Posted January 28, 2009 Can anyone help me with the add script, I can't find the right one that pick the right id! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/141975-delete-image-file-retrieving-name-from-mysql/#findComment-748431 Share on other sites More sharing options...
DjMikeS Posted January 28, 2009 Share Posted January 28, 2009 http://nl.php.net/unlink... So...in your script that would be... <?php unlink ("/destaques/". $_GET['id'] ."); ?> Notice that I used the code tags...you should do so to! Quote Link to comment https://forums.phpfreaks.com/topic/141975-delete-image-file-retrieving-name-from-mysql/#findComment-748439 Share on other sites More sharing options...
lordshoa Posted January 28, 2009 Share Posted January 28, 2009 Do not know the feild so guessed but you will work it out from the it will be from the mysql result $variable = $query_row['image'] unlink($variable); Quote Link to comment https://forums.phpfreaks.com/topic/141975-delete-image-file-retrieving-name-from-mysql/#findComment-748446 Share on other sites More sharing options...
jomagi Posted January 28, 2009 Author Share Posted January 28, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/141975-delete-image-file-retrieving-name-from-mysql/#findComment-748476 Share on other sites More sharing options...
landavia Posted January 29, 2009 Share Posted January 29, 2009 horay... the problem solved please add to above (topic title) Solved sry 4 late respond.. Quote Link to comment https://forums.phpfreaks.com/topic/141975-delete-image-file-retrieving-name-from-mysql/#findComment-750143 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.