Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ondelete trigger remove file

Status
Not open for further replies.

KryptoS

Programmer
Feb 7, 2001
240
BE
Hello,

I don't know if this is a good way. But I'm using cascade delete. E.g. I have a table tbl_comments and a table tbl_files. To each comment I can attach more files. The files are stored on my harddisk.

With cascade deleting, I delete a comment and all the file records are deleted. No problem so far

But how can I delete the file from my harddisk? I've read somewhere that you can do this by writing a trigger on delete. But I've no knowledge about triggers. Can someone help me on my way or give a good tutorial about triggers?
In my tbl_files i've offcourse a field where the file is stored.

thanks!

visit my website at
 
Tables in mysql are supported by a real physical file maintained by the operating system.
If you delete all the rows from a table the physical table remains and you can add more data in.
To physicaly remove the file would require you to issue a DROP statement.
.
So what are you trying to do exactly it looks a little confused.
 
Hmm I don't know if I made myself clear.

I'm building a website. Where you can make a comment. And upload multiple files to that comment. Those files are stored in the table tbl_files. And upload to a path e.g. I want to delete those files. Not the table-file.

visit my website at
 
Ah got you !.
Probabby not, you could do something in a trigger after a delete from a row (I've never actualy done this) but the trigger can't talk out to the operating system to delete the file (as far as I can see there is no syntax or functions to call the OS)
What you might be able to do is to get the trigger to write a row to a table which has the file name in, then your client code (assume it's PHP) can read that table and for each row delete the file.
You need at least MYSQL 5.0.2
The trigger syntax is at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top