SitePoint Sponsor |
|
User Tag List
Results 1 to 10 of 10
Thread: Help with deleting images
-
Jan 20, 2003, 09:45 #1
- Join Date
- Mar 2000
- Location
- Victoria, BC
- Posts
- 230
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Help with deleting images
Could somebody help me with this script. It deletes a members images from their members menu, but it does not delete the images from the server.
When it creates the images it creates a full size and thumbnail, but these are not getting deleted from the server when the user deletes them from their account.
Could somebody wiser than me please help.
Code:<?php session_start(); if($session_access == false) { header("location: ./error.php?error=session"); } include('i.setup.php'); include('i.connection.php'); include('i.function.php'); if($mode == "delete") { $query = mysql_query("SELECT image_id FROM image WHERE image_member_id = '$session_member_id' and image_status = 'A' ORDER BY image_id"); while($data = mysql_fetch_object($query, $db)) { if(${"checkbox" . $data->image_id} == 1) { $sql = "UPDATE image SET image_status='D' WHERE image_id = '$data->image_id'"; $result = mysql_query($sql); } } } ?> <html> <head> <title><?php print($page_title); ?></title> <meta name="description" content="<?php print($page_desc); ?>"> <meta name="keywords" content="<?php print($page_key); ?>"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <?php include('i.style.php'); ?> <script language="javascript"> function copyit(theField) { var tempval=eval("document.home."+theField) tempval.focus() tempval.select() therange=tempval.createTextRange() therange.execCommand("Copy") } function new_window(mypage, myname, w, h, scroll) { var winl = (screen.width - w) / 2; var wint = (screen.height - h) / 2; winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable' win = window.open(mypage, myname, winprops) if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); } } function jp_delete(field) { var agree = confirm("Are you sure you want to delete the selected images?"); if(agree) { document.home.action = "<? echo $PHP_SELF; ?>?mode=delete"; document.home.submit(); } } </script> </head> <body marginwidth="0" marginheight="0" leftmargin="0" topmargin="0" rightmargin="0"> <table width="100%" cellpadding="0" cellspacing="0"> <?php include('i.header.php'); ?> <tr> <td valign="top"> <table cellpadding="0" cellspacing="0"> <tr> <td><font face="verdana" size="1"> </font></td> </tr> <tr> <td><font face="verdana" size="1"> </font></td> <td valign="top"> <table cellpadding="0" cellspacing="0"> <?php include('i.tab.php'); ?> </table> </td> <td><font face="verdana" size="1"> </font></td> <td valign="top" width="100%" height="100%"> <table width="100%" height="100%" cellpadding="0" cellspacing="0"> <tr> <td><font face="verdana" size="1"> </font></td> <td width="100%" height="100%"> <table width="100%" height="100%" cellpadding="0" cellspacing="0"> <tr> <td><img src="./images/heading.control.gif"></td> </tr> <tr> <td height="8" background="images/hr.gif"></td> </tr> <tr> <td><font face="verdana" size="1"> </font></td> </tr> <tr> <td> <table> <?php $query = mysql_query("SELECT member_name FROM member WHERE member_id = '$session_member_id'"); $data = mysql_fetch_object($query, $db); $query = mysql_query("SELECT image_id, image_size FROM image WHERE image_member_id = '$session_member_id' and image_status = 'A'"); while($data2 = mysql_fetch_object($query, $db)) { $size = $size + $data2->image_size; } $rows = mysql_num_rows($query); ?> <tr> <td> <font face="verdana" size="1"> Welcome <b><?php print($data->member_name); ?></b>!<br><br> You have <b><?php print($rows); ?></b> images hosted.<br> <?php $file_size = round(($size/1024), 2); if($file_size > 1024) { ?> Space used <b><?php print(round(($file_size/1024), 2)); ?> mb</b>. <?php } else { ?> Space used <b><?php print($file_size); ?> kb</b>. <?php } ?> </font> </td> </tr> </table> </td> </tr> <tr> <td><font face="verdana" size="1"> </font></td> </tr> <tr> <td><img src="./images/heading.manager.gif"></td> </tr> <tr> <td height="8" background="images/hr.gif"></td> </tr> <tr> <td><font face="verdana" size="1"> </font></td> </tr> <?php $query = mysql_query("SELECT image_id, image_name, image_ext, image_caption, image_width, image_height, image_size FROM image WHERE image_member_id = '$session_member_id' and image_status = 'A' ORDER BY image_id"); $rows = mysql_num_rows($query); if($rows == 0) { ?> <tr> <td> <font face="verdana" size="1">There are no images at this time.</font> </td> </tr> <?php } else { ?> <form name="home" method="post"> <input type="hidden" name="list_num" value="<?php print($rows); ?>"> <tr> <td> <table width="100%" cellpadding="4" cellspacing="0"> <tr> <td align="center"><font face="verdana" size="1"><b>Delete</b></font></td> <td align="center"><font face="verdana" size="1"><b>Image</b></font></td> <td><font face="verdana" size="1"><b>Caption</b></font></td> <td align="center"><font face="verdana" size="1"><b>Width/Height</b></font></td> <td align="center" nowrap><font face="verdana" size="1"><b>Size[kb]</b></font></td> </tr> <?php if($startat == "") { $startat = 0; } if($perpage == "") { $perpage = 5; } $line = $startat; $templine = 0; $recordnum = 0; $total_views = 0; $count_total = 0; $max = mysql_num_rows($query); while($data = mysql_fetch_object($query, $db)) { if($templine < $perpage and $line < $max) { if($line == $recordnum) { $line++; $templine++; if(($thisrow%2) == 0) { $color = "#EEEEEE"; $thisrow++; } else { $color = "#FFFFFF"; $thisrow++; } ?> <tr bgcolor="<?php print($color); ?>"> <td align="center"><input type="checkbox" name="checkbox<?php print($data->image_id); ?>" value="1"></td> <?php if($data->image_ext == "gif") { ?> <td align="center"><a href="javascript:new_window('./detail.php?id=<?php print($data->image_id); ?>', 'popup', '<?php print($data->image_width); ?>', '<?php print($data->image_height); ?>', 'no');"><img src="./hosted/<?php print($data->image_name); ?>.<?php print($data->image_ext); ?>" height="50" border="1"></a></td> <?php } else { ?> <td align="center"><a href="javascript:new_window('./detail.php?id=<?php print($data->image_id); ?>', 'popup', '<?php print($data->image_width); ?>', '<?php print($data->image_height); ?>', 'no');"><img src="./hosted/thumb_<?php print($data->image_name); ?>.<?php print($data->image_ext); ?>" height="50" border="1"></a></td> <?php } ?> <td width="100%"> <table cellpadding="0" cellspacing="0"> <?php if($data->image_caption == "") { ?> <tr> <td align="right"><font face="verdana" size="1">caption: </font></td> <td colspan="2"><font face="verdana" size="1">n\a</font></td> </tr> <?php } else { ?> <tr> <td align="right"><font face="verdana" size="1">caption: </font></td> <td colspan="2"><font face="verdana" size="1"><?php print($data->image_caption); ?></font></td> </tr> <?php } ?> <tr> <td align="right"><font face="verdana" size="1">link: </font></td> <td nowrap><font face="verdana" size="1"><input type="text" name="link<?php print($data->image_id); ?>" class="form" value="<?php print($page_url); ?>/hosted/<?php print($data->image_name); ?>.<?php print($data->image_ext); ?>" style="width: 425px;"> </font></td> <td nowrap><a href="javascript:copyit('link<?php print($data->image_id); ?>');"><img src="./images/bu.copy.gif" border="0"></a></td> </tr> </table> </td> <td align="center"><font face="verdana" size="1"><?php print($data->image_width); ?>/<?php print($data->image_height); ?></font></td> <?php $file_size = round(($data->image_size/1024), 2); if($file_size > 1024) { ?> <td align="center" nowrap><font face="verdana" size="1"><?php print(round(($file_size/1024), 2)); ?> mb</font></td> <?php } else { ?> <td align="center" nowrap><font face="verdana" size="1"><?php print($file_size); ?> kb</font></td> <?php } ?> </tr> <?php } $recordnum++; } } ?> <tr> <td colspan="6" height="8" background="images/hr.gif"></td> </tr> <tr> <td align="center"> <a href="javascript:jp_delete();"><img src="./images/bu.delete.gif" border="0"></a> </td> <td colspan="6"> <table width="100%"> <tr> <td align="center" nowrap> <font face="verdana" size="1"> <?php if(($startat + $perpage) < $max) { print(($startat + 1) . " - " . ($startat + $perpage) . " of " . $max); } else { print(($startat + 1) . " - " . $max . " of " . $max); } ?> </font> </td> <td align="center" nowrap> <a href="<?php print($PHP_SELF . "?startat=" . $startat . "&perpage=5" . "&sort_by=" . $sort_by); ?>"><img src="./images/bu.5.gif" border="0"></a> <a href="<?php print($PHP_SELF . "?startat=" . $startat . "&perpage=10" . "&sort_by=" . $sort_by ); ?>"><img src="./images/bu.10.gif" border="0"></a> <a href="<?php print($PHP_SELF . "?startat=" . $startat . "&perpage=15" . "&sort_by=" . $sort_by ); ?>"><img src="./images/bu.15.gif" border="0"></a> <a href="<?php print($PHP_SELF . "?startat=" . $startat . "&perpage=20" . "&sort_by=" . $sort_by ); ?>"><img src="./images/bu.20.gif" border="0"></a> <a href="<?php print($PHP_SELF . "?startat=" . $startat . "&perpage=25" . "&sort_by=" . $sort_by ); ?>"><img src="./images/bu.25.gif" border="0"></a> </td> <td align="right" nowrap> <font face="verdana" size="1"> <? if(($startat - $perpage) < 1) { ?> <a href="<?php print($PHP_SELF . "?startat=0&perpage=" . $perpage . "&sort_by=" . $sort_by); ?>">Previous</a> <?php } else { ?> <a href="<?php print($PHP_SELF . "?startat=" . ($startat - $perpage)); ?>&perpage=<?php print($perpage) . "&sort_by=" . $sort_by; ?>">Previous</a> <?php } ?> : <?php if($line < $max) { ?> <a href="<?php print($PHP_SELF . "?startat=" . ($startat + $perpage)); ?>&perpage=<?php print($perpage) . "&sort_by=" . $sort_by; ?>">Next</a> <?php } else { ?> <a href="<?php print($PHP_SELF . "?startat=" . $startat); ?>&perpage=<?php print($perpage) . "&sort_by=" . $sort_by; ?>">Next</a> <?php } ?> </font> </td> </tr> </table> </td> </tr> </table> </td> </tr> </form> <?php } ?> <tr> <td height="100%"><font face="verdana" size="1"> </font></td> </tr> <tr> <td height="8" background="images/hr.gif"></td> </tr> </table> </td> <td><font face="verdana" size="1"> </font></td> </tr> </table> </td> </tr> </table> </td> </tr> <?php include('i.footer.php'); ?> </table> </body> </html>
-
Jan 20, 2003, 17:59 #2
- Join Date
- Mar 2000
- Location
- Victoria, BC
- Posts
- 230
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Could anybody help. I think this is the sub routine that does the deleting.
Code:if($mode == "delete") { $query = mysql_query("SELECT image_id FROM image WHERE image_member_id = '$session_member_id' and image_status = 'A' ORDER BY image_id"); while($data = mysql_fetch_object($query, $db)) { if(${"checkbox" . $data->image_id} == 1) { $sql = "UPDATE image SET image_status='D' WHERE image_id = '$data->image_id'"; $result = mysql_query($sql); } } }
-
Jan 20, 2003, 20:11 #3
- Join Date
- Aug 2002
- Location
- Burpengary, Australia
- Posts
- 4,495
- Mentioned
- 0 Post(s)
- Tagged
- 1 Thread(s)
That code will delete from a database, do you want the file deleted as well?? If so, then try this
PHP Code:if($mode == "delete") {
$query = mysql_query("SELECT image_id, image_file FROM image WHERE image_member_id = '$session_member_id' and image_status = 'A' ORDER BY image_id");
while($data = mysql_fetch_object($query, $db)) {
if(${"checkbox" . $data->image_id} == 1) {
$sql = "UPDATE image SET image_status='D' WHERE image_id = '$data->image_id'";
$result = mysql_query($sql);
unlink($data->image_file);
}
}
}
-
Jan 20, 2003, 20:49 #4
- Join Date
- Mar 2000
- Location
- Victoria, BC
- Posts
- 230
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks I will give that a try.
-
Jan 20, 2003, 21:33 #5
- Join Date
- Mar 2000
- Location
- Victoria, BC
- Posts
- 230
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I tried your code, but I am having trouble replacing "image_file" in the two locations. Here is a copy of my database.
http://www.avidnewmedia.com/~myphoto...s/database.gif
It renames the file from "image_original" into 2 fields "image_name" and "image_ext". How do I call both of those?
It also creates a second file to be used as a thumbnail called.... "thumb_NEW NAME OF FILE".
So I need to delete the file it creats and its correspondign thumbnail that is created.
-
Jan 20, 2003, 21:55 #6
- Join Date
- Oct 2001
- Location
- Texas
- Posts
- 598
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
havent read everything but try this
change
unlink($data->image_file);
to this
unlink($data->image_name.$data->image_ext);
-
Jan 20, 2003, 22:05 #7
- Join Date
- Aug 2002
- Location
- Burpengary, Australia
- Posts
- 4,495
- Mentioned
- 0 Post(s)
- Tagged
- 1 Thread(s)
PHP Code:if($mode == "delete") {
$query = mysql_query("SELECT image_id, image_original FROM image WHERE image_member_id = '$session_member_id' and image_status = 'A' ORDER BY image_id");
while($data = mysql_fetch_object($query, $db)) {
if(${"checkbox" . $data->image_id} == 1) {
$sql = "UPDATE image SET image_status='D' WHERE image_id = '$data->image_id'";
$result = mysql_query($sql);
unlink($data->image_original);
}
}
}
-
Jan 20, 2003, 22:06 #8
- Join Date
- Mar 2000
- Location
- Victoria, BC
- Posts
- 230
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I get the error
Warning: unlink() failed (No such file or directory) in /home/myphotos/public_html/home.php on line 22
when I try that. Any other ideas?
-
Feb 15, 2004, 17:30 #9
- Join Date
- Feb 2004
- Location
- some place south
- Posts
- 31
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hiya, its a safe mode error. check my thread here.
http://www.sitepoint.com/forums/show...44#post1107744
-
Feb 15, 2004, 17:44 #10
- Join Date
- Sep 2001
- Location
- Panama
- Posts
- 2,181
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Not really. That error means that unlink wasn't able to execute because it couldn't find the file.
Verify the path to the file and also check that the file is there. You could also use file_exists to check if the file is there before deleting it and avoid the error message.Community Guidelines | Community FAQ
"He that is kind is free, though he is a slave;
he that is evil is a slave, though he be a king." - St. Augustine
Bookmarks