Hi,
I have a form where people can upload images to the server and it's working fine, I made another form that lets them change the image, and that works fine also, the problem is, how do I delete the old image on the server?
I tried adding this code into a custom code event:
but it doesn't work, so I tried putting any type of code in an event, like a simple echo, but I get no response, I tried both controller and view, ad well as different places in the event order, but still no response, so how do I add a custom event? Am I missing something?
PS: the above code works elsewhere on the site, in an article, and the $fullimgpath also works because in the form I use it to display the old image to the user.
I have a form where people can upload images to the server and it's working fine, I made another form that lets them change the image, and that works fine also, the problem is, how do I delete the old image on the server?
I tried adding this code into a custom code event:
if($fullimgpath!=''){
unlink ($fullimgpath);
}
but it doesn't work, so I tried putting any type of code in an event, like a simple echo, but I get no response, I tried both controller and view, ad well as different places in the event order, but still no response, so how do I add a custom event? Am I missing something?
PS: the above code works elsewhere on the site, in an article, and the $fullimgpath also works because in the form I use it to display the old image to the user.
Hi mankind1023,
Are you adding PHP tags round your code?
Bob
Are you adding PHP tags round your code?
<?php
if($fullimgpath!=''){
unlink ($fullimgpath);
}
?>
Bob
I have tried with and without PHP tags, and in different areas of the form.
PS: is there a native way to do this? I'm having users upload a new image to replace the older one but that simply changes the db info, the file is left.
PS: is there a native way to do this? I'm having users upload a new image to replace the older one but that simply changes the db info, the file is left.
Hi mankind1023,
There's been a thread on this before if you hunt around.
When the form is submitted you need to check if there is a new file, if there is look up the value of the old one; then build a corresponding path and delete the old file (preferably after checking that the new one has uploaded correctly).
Bob
There's been a thread on this before if you hunt around.
When the form is submitted you need to check if there is a new file, if there is look up the value of the old one; then build a corresponding path and delete the old file (preferably after checking that the new one has uploaded correctly).
Bob
This topic is locked and no more replies can be posted.