Delete and create file and folders

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kuzure
    New Member
    • Dec 2006
    • 48

    Delete and create file and folders

    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.
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    [PHP]<?php
    exec("del C:\\somefile.tx t");
    ?>[/PHP]

    Comment

    • kuzure
      New Member
      • Dec 2006
      • 48

      #3
      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.

      Comment

      • vssp
        Contributor
        • Jul 2006
        • 268

        #4
        using unlink function to delete the files

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Yeah try
          [PHP]<?php
          unlink("C:/testing.txt");
          ?>
          [/PHP]
          Notice the forward slash

          Comment

          • kuzure
            New Member
            • Dec 2006
            • 48

            #6
            Originally posted by r035198x
            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.tx t" because there are unwanted data store in there. So, after I delete it, I need to create a same file "testing.tx t" 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.

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by kuzure
              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.tx t" because there are unwanted data store in there. So, after I delete it, I need to create a same file "testing.tx t" 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

              Comment

              • kuzure
                New Member
                • Dec 2006
                • 48

                #8
                Dear r035198x,

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

                Best Regards

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by kuzure
                  Dear r035198x,

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

                  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.

                  Comment

                  • kuzure
                    New Member
                    • Dec 2006
                    • 48

                    #10
                    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.

                    Comment

                    Working...