I have an existing script that doesn’t seem to work any longer and could use some help debugging it.
The script allows us to use a web browser to add/edit/ files from a web page. The web page is database driven and shows the available files that have been uploaded. Next to each file is a ‘delete’ icon which should allow us to delete that file from the list, and I assume from the database as well.
When I click the delete icon the appropriate ‘are you sure you want to delete this file’ prompt comes up but it doesn’t actually delete the file and gives a response that the file has not been deleted. I think this is a code issue but could it be a server/db permission issue?
Below is what I think is the relevant code.
[php]
//edit-delete switch
if ( isset($_GET['mode']) && isset($_GET['id']) ) {
$showform = false;
$material_exists = $db->get_row("SELECT * FROM Materials WHERE id='$_GET[id]'");
if ($material_exists) {
$curr_File = $material_exists;
$curr_cat = $db->get_row("SELECT * FROM Categories WHERE id='$curr_material->category_id'");
$material_dir .= $curr_cat->folder;
$large_material_dir .= $curr_cat->folder;
$material_view_dir .= $curr_cat->folder;
$max_order = $db->get_var("SELECT MAX(ordering) FROM Materials WHERE category_id='$curr_cat->id'");
switch ($_GET['mode']) {
case 'edit':
$edit = true;
$showform = true;
break;
case 'del':
$response_msg = '';
$curr_material = $db->get_row("SELECT * FROM Materials WHERE id='$_GET[id]'");
$curr_cat = $db->get_row("SELECT * FROM Categories WHERE id='$_GET[cid]'");
$material_dir .= $curr_cat->folder;
if ( unlink($material_dir . $curr_material->filename) ) {
$db->query("DELETE FROM Materials WHERE id='$_GET[id]'");
$db->query("UPDATE Materials SET ordering=ordering-1 WHERE category_id='$curr_cat->id' AND ordering > '$curr_material->ordering'");
$response_title = 'File Deleted';
$response_msg .= $add_msg;
} //if()
else {
$response_title = 'Error';
$response_msg = 'File not deleted.<br/>';
$response_msg .= 'Please try again.<br/>';
$response_msg .= $return_msg;
} //else
break;
[/php]
I can provide the full php page/code if needed.
Thanks for any help or insights you might have.
R.