SitePoint Sponsor

User Tag List

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

    Sending images for approval

    Hello all,

    Since i have a gallery page where every1 can upload photos freely, i would like to have some way to avoid those who would use this for spamming.

    My idea is, making another folder for photos that have been uploaded by users, and when i log as an admin i can select which images to send to the Gallery folder, and which of them to delete.

    I need help on how to make this transferring part (cutting from 1 folder and pasting in the other)

    Thanks in advance,
    Ulthane

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What I would do is give each image an ID in the database, and also have a field called Approved (Yes/No). When an image is uploaded then the default value is No.

    Your admin page would get all items where Approved=No and you could then select each one and update it to Yes if it is OK.
    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)
    hmm, the problem is that those photos are not stored or linked to any DB, they are just uploaded into a folder
    is there any other way of doing this? if not than ill have to change the way they are uploaded/displayed, but i'd really preffer to hear another way if there is any..

  4. #4
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there are photo gallery type applications available which can tie to a folder.

    put the application in your secure admin area and use it to manage your photos

  5. #5
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ulthane View Post
    hmm, the problem is that those photos are not stored or linked to any DB, they are just uploaded into a folder
    is there any other way of doing this? if not than ill have to change the way they are uploaded/displayed, but i'd really preffer to hear another way if there is any..
    Remember, way back, in your early questions, when I suggested using a database properly?
    Ian Anderson
    www.siteguru.co.uk

  6. #6
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    well i just didnt think i would need a table in the DB for that too :P
    i was almost sure it can be done with the objFSO stuff or so...

    perheps i could just add a table to my DB with just a link to that folder, to store the images names, and do what u said before with the yes/no record..

    also another thing, i just logged into my site on brinkster and i got this msg on every page that displays something from the db.. what does it means?

    Microsoft OLE DB Provider for ODBC Drivers error '8007000e'
    [Microsoft][ODBC Microsoft Access Driver] System resource exceeded.

    Thanks in advance,
    Ulthane

  7. #7
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    With FSO then the way to do it would be ...

    Have a Temp folder within the DB folder
    All images upload to Temp at first
    You have a script to view images in Temp, and if OK you click a box which uses FSO to move the image to the gallery folder

    Regarding the error message, that sounds like something you need to ask Brinkster, maybe via their LiveChat system.
    Ian Anderson
    www.siteguru.co.uk

  8. #8
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Have a Temp folder within the DB folder
    All images upload to Temp at first
    You have a script to view images in Temp, and if OK you click a box which uses FSO to move the image to the gallery folder
    thats excactly what i want to know! , how can i do that? (just the moving file from folder to folder part)

  9. #9
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    objFSO.MoveFile SourceFile, DestinationFolder
    Ian Anderson
    www.siteguru.co.uk

  10. #10
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    hmm, got into a small problem

    on page1.asp :
    Code:
    <a href="page2.asp?move=db/temp/<%=objFile.Name%>">accept</a>
    Page2.asp :
    Code:
    Dim fso, MyFile, FileName
    Set fso = server.CreateObject("Scripting.FileSystemObject")
    Set FileName = Request.Querystring("move")
    Set MyFile = fso.GetFile(Server.Mappath(FileName))
    MyFile.moveFile FileName, db/photos/  ' Throws error on this line...
    set MyFile = nothing
    set fso = nothing
    So i guess i did it wrong ? =P

  11. #11
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    FileName needs to have the full path and name of the ACTUAL FILE ALREADY ON THE SERVER. How about actually reading the VBScript reference manual? (I've linked this to you previously).

    Code:
    Dim fso,MyFile,FileName,NewLocation
    Set fso = server.CreateObject("Scripting.FileSystemObject")
    FileName = Request.Querystring("move")
    MyFile = Server.MapPath("/accountname/db/temp/" & FileName)
    NewLocation = Server.MapPath("/accountname/db")
    fso.MoveFile MyFile, NewLocation
    set fso = nothing
    UNTESTED!

    And you should really also include a test to be sure that the file to be moved does actually exist before trying to move it. (FileExists method).
    Ian Anderson
    www.siteguru.co.uk

  12. #12
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    it gives an error that the "file already exists", even when there's no file with the same name on the photos folder (the folder im trying to move the file to...)

    also that just pops up the question, what will happen if there'll be 2 photos with the same name? going to need something to set a unique name to each photo...

  13. #13
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I thought you already had a unique name, via the uploader class script?

    Like I said, my example was untested and was to provide guidance only.
    Ian Anderson
    www.siteguru.co.uk

  14. #14
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    well there is, in case there is a file called "pic.jpg" already then it'll uplaod it as "pic1.jpg" and thats with lewis moten's way, the point is that here it says file already exists even if there's no file with the same name on that folder

  15. #15
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    So what code are YOU using? (I hope you're not using my example code exactly!)
    Ian Anderson
    www.siteguru.co.uk

  16. #16
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    well i didnt change it much, since it was the code i used in the first place, just with a few changes of what u gave me to try and get that moveFile part working

    Code:
    Dim fso,MyFile,FileName,NewLocation
    Set fso = server.CreateObject("Scripting.FileSystemObject")
    FileName = Request.Querystring("move")
    MyFile = fso.GetFile(Server.Mappath(FileName))
    NewLocation = Server.MapPath("db/photos/")
    fso.MoveFile MyFile, NewLocation
    set fso = nothing
    While "move" contains the path to the image with the image name (db/temp/Name.jpg)

  17. #17
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Here's a working version (tested on my localhost, using a random photo):

    Code:
    <%
    Dim fso,FileToMove,NewLocation
    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    FileToMove = Server.Mappath("db/temp/DSCN0663.JPG")
    NewLocation = Server.MapPath("db") & "\"
    fso.MoveFile FileToMove, NewLocation
    set fso = nothing
    %>
    The issue I found was that the NewLocation variable needed a \ added to it.

    Remember that you still should extract the file name itself and check if that file already exists in the db folder before trying to move from temp. And here's a working example of this:

    Code:
    <%
    Dim fso,OldLocation,FileToMove,NewLocation,tmpArr
    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    OldLocation = Server.Mappath("db/temp/DSCN0663.JPG")
    tmpArr = Split(OldLocation,"\")
    FileToMove = tmpArr(Ubound(tmpArr))
    NewLocation = Server.MapPath("db") & "\"
    If Not fso.FileExists(NewLocation & FileToMove) Then
    	fso.MoveFile OldLocation, NewLocation
    	Response.Write ("<p>File '" & FileToMove & "' was moved</p>")
    Else
    	Response.Write ("<p>A file called '" & FileToMove & "' already exists in the folder</p>")
    End If
    set fso = nothing
    %>
    Ian Anderson
    www.siteguru.co.uk

  18. #18
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks for all the help siteguru
    I've also just added moving with unique name incase the file already exists...

    Code:
    Dim fso,OldLocation,FileToMove,NewLocation,tmpArr
    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    FileName = Request.Querystring("move")
    MyFile = Server.MapPath("db/temp/" & FileName)
    tmpArr = Split(MyFile,"\")
    FileToMove = tmpArr(Ubound(tmpArr))
    NewLocation = Server.MapPath("db") & "\" & ("Photos") & "\"
    If Not fso.FileExists(NewLocation & FileToMove) Then
    	fso.MoveFile MyFile, NewLocation
    Else
        i=GenIt(1024)
        strName=fso.GetBaseName(FileName)
        strExt=fso.GetExtensionName(FileName)
        strNewName=strName & "_" & i & "." & strExt
        MyFile = Server.MapPath("db/temp/" & FileName)
        NewLocation = Server.MapPath("db") & "\" & ("Photos") & "\" & strNewName
        fso.MoveFile MyFile, NewLocation
    End If
    set fso = nothing
    
    Function GenIt(iLimit)
    Randomize
     GenIt=Int(RND()*iLimit)+1
    end Function

  19. #19
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Of course the file was not found - it doesn't exist! (Just because you have created a unique name, you still haven't RENAMED the original file in temp to the new file name).

    You need to rename the existing file to the new name THEN move it to Photos.

    PS - why do you have it as ("Photos") in your code? What is the point of that? The ( ) are not needed. I would write that line like this:

    Code:
    NewLocation = Server.MapPath("db") & "\Photos\"
    Ian Anderson
    www.siteguru.co.uk


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
  •