SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    deleting a specific file from a folder

    hello everyone
    i've been working on a form to delete images from a folder, but the method is not the same as deleting an image from the DB, so ill need a hand
    i have a list of images inside the folder, and againts each image i want a button to Delete the file...any ideas on how to make the delete function?

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    FileSystemObject.

    If you know the name of the file, and its location (Server.Mappath) then it is easy.
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    yup, im using this method, but still cannot find out how to make that deleting button work

    i've tried the following thing with javascript:
    Code:
    <td><a href="photos/JavaScript:del(<&#37;=objFile.Name%>)"><font size="2" color="#FF0000"><u>Delete</u></font></a></td>
    Code:
    <script type="text/javascript">
    	    function del(name) {
    	        if (confirm("preparing to delete " + name ")) {
    	            self.location.href = "gallery_delete2.asp?delete=" + name;
    	            return true;
    	        }
    	    }
    	</script>
    this method appears to send to gallery_delete2.asp correctly, but what should gallery_delete2.asp contain ?

    edit * hmm, i've just tried and i noticed it doesn't work correctly, it takes me to the address of the photo not to gallery_delete2

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Why are you mixing Javascript code in with the href path? That is entirely non-valid code! Why not simply do ...

    Code:
    <a href="gallery_delete2.asp?delete=<%=objFile.Name%>">Delete</a>
    Then you simply use FSO and the .delete method. Example ...

    Code:
    Dim fso, MyFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set MyFile = fso.GetFile(Server.Mappath("photos/photoname.jpg")
    MyFile.Delete
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thanks for the reply but that just doesn't work out , it sends to gallery_delete2 but it gives error, i've tried to edit the following line million of times(and even the whole code sometimes):

    Code:
    Set MyFile = fso.GetFile(Server.Mappath("photos/photoname.jpg")
    still no luck, what should come instead of that "photoname.jpg" thingy?

  6. #6
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    As I have said before - DO NOT USE EXAMPLE CODE LITERALLY! THINK about what is being said, and try to UNDERSTAND it, before trying to use it.

    Use Request.Querystring("delete") to get the file name to be deleted.

    Use the result in the Mappath.

    AND CHECK FOR VALID DATA BEFORE YOU DO ANYTHING WITH IT!!!!

    And ... saying "It gives an error" without saying WHAT the error is - well that's simply a waste of typing.
    Ian Anderson
    www.siteguru.co.uk

  7. #7
    SitePoint Zealot gidday's Avatar
    Join Date
    Jan 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Siteguru

    It's about time you started getting a bit pissed off with ulthane here. With the amount of time you have put in with him I hope he credits you as the developer of his work once it is completed.
    Joe
    "All that is necessary for the triumph of evil
    is that good men do nothing."


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •