Obviously, your javascript (on the client side) will have to call the URL (on the server side) to remove the image selected by the user. I suggest that at the moment you are doing this statically (if later you want to move on to something more dynamic, the step of becoming ajax in a rather small size.
As Set Sail Media said, you will need to transfer the username and location identifier to your server when you click the delete button. One way to do this:
When rendering your gallery in HTML / javascript for each image, you have one under it that will contain the necessary information, and the submit button will simply cause the script to be deleted from your server. An example of a form you can do is:
<form name="deleteImageX" method="GET" target="your.server.org/deleteImage.php"> <input type="hidden" name="userName" value="theUserNameAssociatedWithThePicture" /> <input type="hidden" name="locationId" value="locationOfThePicture" /> <input type="submit" value="delete"/> </form>
This form will save the required value in hidden fields that will not be displayed on the web page, but will still be sent to the server when you click the submit button.
(for a little history, the method used here is GET, because HTML AFAIK does not support the DELETE method (which would be suitable in our case)).
The GET method will call the script "your.server.org/deleteImage.php". In this script, you will have all the necessary information (username / locationId) to delete the image using the variables $ _GET ['username'] and $ _GET ['locationId']. Then, as you mentioned, you will need to use the unlink method to actually delete the file from the server.
Finally, once this is done, you need to redirect the php script so that after deleting the image you will again display the gallery (for example). This can be done by calling the script if you have some kind of template engine or the php header function is called.
I hope this thread was what you expected, and I hope it was useful.
Yours faithfully,
Bear
bear foot
source share