By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,303 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,303 IT Pros & Developers. It's quick & easy.

Delete and create file and folders

P: 48
Dear friends,

I had host a server and now I have some problem.

I want to click on my web page and delete certain files in my computer. For instance, there is .txt file in my C Drive and I want to delete it, lets assume the file is at "C:\testing.txt". So, since I host a server, I want to delete this file when I click some buttons at the web page. Is that possible?

Appreciate for any reply. Thank you.

Best Regards.
Mar 1 '07 #1
Share this Question
Share on Google+
9 Replies


Motoma
Expert 2.5K+
P: 3,235
[PHP]<?php
exec("del C:\\somefile.txt");
?>[/PHP]
Mar 1 '07 #2

P: 48
Dear Motoma,

I had tried the code, but it did not delete the file I chosen. By the way, after I tried the code, my Kaspersky detect a virus... ...It is coincidence? Or the code got problem? ^^haha. Dont get me wrong, I'm didnt mean that you send me virus, maybe the code will attract something, i guess... ... I believe this is a forum that helping us to solve problem. I had gain many knowledges here.

By the way, thanks for the reply, I will try the code again.

Best Regards.
Mar 2 '07 #3

100+
P: 268
using unlink function to delete the files
Mar 2 '07 #4

10K+
P: 13,264
Yeah try
[PHP]<?php
unlink("C:/testing.txt");
?>
[/PHP]
Notice the forward slash
Mar 2 '07 #5

P: 48
Yeah try
[PHP]<?php
unlink("C:/testing.txt");
?>
[/PHP]
Notice the forward slash
Dear friend,

Thank you!!! It works!!!

Erm...then if I want to create a file, how can I do it? I mean I need to delete the file,for instance, "testing.txt" because there are unwanted data store in there. So, after I delete it, I need to create a same file "testing.txt" back to the same place, of course, with empty data.

By the way, can anyone tell me how to create a "browse box"? It called a browse box right? haha^^. Something like when I upload photo to friendster, there are a emtpy text box and beside it has a button "browse".

Thanks for the reply.

Best Regards.
Mar 3 '07 #6

10K+
P: 13,264
Dear friend,

Thank you!!! It works!!!

Erm...then if I want to create a file, how can I do it? I mean I need to delete the file,for instance, "testing.txt" because there are unwanted data store in there. So, after I delete it, I need to create a same file "testing.txt" back to the same place, of course, with empty data.

By the way, can anyone tell me how to create a "browse box"? It called a browse box right? haha^^. Something like when I upload photo to friendster, there are a emtpy text box and beside it has a button "browse".

Thanks for the reply.

Best Regards.

Try

[PHP]
<?php
$file = "C:/testing.txt";
if(!file_exists($file)) {
$fout = fopen($file, "w");
}
?>
[/PHP]
For opening the file
Mar 3 '07 #7

P: 48
Dear r035198x,

I dont get the idea. What is this mean anyway "$fout = fopen($file, "w"); "?? Well, I just tried it, but the "testing.txt" file still there, and the data I wrote in "If it works it will be blank later" still remain in the "testing.txt".

Best Regards
Mar 3 '07 #8

10K+
P: 13,264
Dear r035198x,

I dont get the idea. What is this mean anyway "$fout = fopen($file, "w"); "?? Well, I just tried it, but the "testing.txt" file still there, and the data I wrote in "If it works it will be blank later" still remain in the "testing.txt".

Best Regards
I thought you said you have already deleted the file and now want to create a new one in which case that code will create the new file which will be blank.
Mar 3 '07 #9

P: 48
Dear r035198x,

Thanks for the reply. I know what happen already, I think I made a big mistake. haha^^.

Hrm, actually, instead of delete and replace a same file, is there any other way such like delete the data ONLY?

Wow, If I only read books to find out, it might take more time. haha^^ PHP really tough.

Best Regards.
Mar 4 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.