I am not sure how to include this functions dynamically
Based on your question and your code, it looks like you are capable of deleting or renaming the files but are looking for work flow advice.
I give the following suggestions. If you want code, I am happy to supply my solutions, but the scope of an interface is rather large and needs some clarification first. For example,
- Do you have directories that the user navigates?
- Do you want the user to have checkboxes to check individual files (recommended) OR do you want them to be able to enter a file pattern as you example shows (dangerous!)?
My recommendations:
Use a table to display the files. Above the table include buttons to "Delete Selected", "Cancel"
Include the following columns in the table:
- Checkbox (for selecting multiple files if this is desired)
- Filename (just text and can be the label portion of the checkbox)
- Editable input with filename allowing user to rename
- Input Button = "Rename" (to rename individual file)
- Input Button = "Delete" (to delete individual file)
- Thumbnail image which they can click on to see a full sized image.
The table is within a form so that each <input>
with a name
property will end up in $_POST
For example, the inputs for renaming a file and submitting it looks like this:
<td><input type=text name=filer-<?php echo encodestr($filefull) ?> value='<?php echo $name ?>'></td>
<td><input type="submit" name="fprename-<?php echo encodestr($filefull) ?>" value="Rename" onClick='return confirm("Do you want to rename this file?");'></td>
where $filefull
is the full existing path to the file and $name
is without the path. When clicking on the Rename button, $_POST
will contain elements with each filename prefixed with filer-
so I can easily recognize them. I know which one to rename or delete based on which submit button was pressed which I can tell from the var which is prefixed with fprename-
.
So if I get back from $_POST
a var named $_POST['fprename-/path/myfile.jpg']
, I look for the input var $_POST['filer-/path/myfile.jpg']
and rename the file to the value contained in it (of course checking first that a file with that name doesn't already exist).
Work Flow:
For deleting multiple files
- User selects items using checkboxes for deleting and submits form by clicking on the
Delete Selected
submit button.
- The form
onSubmit
gives a javascript alert()
to allow cancelling the delete request.
- After user confirms, you want to do a Post/Redirect/Get (to prevent multiple form submission). This involves submitting the form to another php (e.g. processFiles.php) which processes the unlink() code you have then redirects back to the userInterface.php.
For deleting or renaming individual files
- User clicks on a submit button in the table next to the individual files.
- The button
onclick
gives a javascript alert()
to allow cancelling the delete or rename request.
- After user confirms, the form will submit. Again, you want to do a Post/Redirect/Get where another php (e.g. processFiles.php) processes the unlink() or rename code then redirects back to the userInterface.php.
In the following example, I don't allow deleting multiple files, only Selecting multiple files - hence the "Select" button at the top instead of a "Delete Selected".
