Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.