jasonc Posted January 7, 2008 Share Posted January 7, 2008 i am able to upload files but when it comes to deleting them it does not work. i look at the html source code before i submit or delete and all looks ok, but i echo the file name and it contains an _ (underline) in place of the . before the extention can anyone suggest what i could be doing wrong <? $uploaddir = "/home/mysite/public_html/images/"; include("dbconfigfile.php"); if ($_POST['d'] == "1") { foreach($_POST as $key => $val) { if ($key != "*.*" && $key != "*" && $key != "d") { // delete file name only from images-filename, but... if the imagelocation is empty then delete the whole entry line from DB. //delete file from folder if exists ! unlink($uploaddir . $key); echo($uploaddir . $key."<br><br><br><br>"); echo($key.' Deleted<br>'); mysql_query("DELETE FROM `images` WHERE `filename` ='" . $key . "' LIMIT 1;") or die(mysql_error()); } } echo("files are not really deleted yet, still working on it."); } else { ?><p align="center">Please note that if you upload a file with the same name as another file you have uploaded, this new file will over write the old file.</p><p align="center">Your Existig Files...</p><p align="center"> <? $dh = opendir($uploaddir); ?><form name="form1" method="post" action=""><input name="d" type="hidden" value="1"><? while (false !== ($filename = readdir($dh))) { $ext = getFileExtension($filename); if(in_array($ext, $allowed)) { ?><input type="submit" name="<?=$filename;?>" value="DELETE"> <?=$filename;?><br><? } } ?></form></p> <form action="" method="POST" enctype="multipart/form-data"> <table width="444" height="218" border="1" align="center"> <tr align="center"> <td height="152" colspan="2"> <? if(isset($_REQUEST['submit']) && $_FILES['imgfile']['name'] != "") { $file = $_FILES['imgfile']['name']; $tmp_file = $_FILES['imgfile']['tmp_name']; $size = $_FILES['imgfile']['size']; $upload = $uploaddir . $file; $ext = getFileExtension($file); if(!in_array($ext, $allowed)) { echo "ERROR: Invalid file extension."; } elseif (move_uploaded_file($tmp_file, $upload)) { // set info about image in mysql $update = mysql_query("INSERT INTO `images` (`imagelocation` , `filename`, `uploadedby`) VALUES ('', '" . $file . "', '" . $_SESSION['adminusername'] . "')") or die(mysql_error()); echo $file."<br>Upload successfully!<br>"; } else { echo "Image upload failed."; } } else { echo("No file uploaded"); } ?> </td> </tr> <tr><td height="28" colspan="2"><div align="right"><input type="file" name="imgfile"><input type="hidden" name="MAX_FILE_SIZE" value="20000"></div></td></tr> <tr><td width="372" height="28"><p>.doc .gif .jpg .wma .mp3 .pdf .ppt .pub .rtf .txt .zip only</p></td><td width="56"><input name="submit" type="submit" value="Upload"></td></tr> </table> </form> <? } } ?> Link to comment https://forums.phpfreaks.com/topic/84893-can-upload-but-not-delete-files/ Share on other sites More sharing options...
papaface Posted January 7, 2008 Share Posted January 7, 2008 Use the [*code][/*code] tags without * Link to comment https://forums.phpfreaks.com/topic/84893-can-upload-but-not-delete-files/#findComment-432813 Share on other sites More sharing options...
Ken2k7 Posted January 7, 2008 Share Posted January 7, 2008 Use the [*code][/*code] tags without * There is a [nobbc] tag. -> Link to comment https://forums.phpfreaks.com/topic/84893-can-upload-but-not-delete-files/#findComment-432821 Share on other sites More sharing options...
jasonc Posted January 7, 2008 Author Share Posted January 7, 2008 change original post with [c ode][/ code] Link to comment https://forums.phpfreaks.com/topic/84893-can-upload-but-not-delete-files/#findComment-432850 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.