Visualizzazione dei risultati da 1 a 8 su 8
  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2007
    Messaggi
    196

    Upload. controllo se il file è un'immagine

    buongiorno ,

    vorrei sapere come si fa a fare un controllo x verificare che il file che stai uploadando sia un file immagine, e se non è un immagine bisogna far restituire un errore..

    grazieeeeee

  2. #2
    Utente di HTML.it L'avatar di fraude
    Registrato dal
    Feb 2004
    Messaggi
    2,870
    Dipende dallo script di upload che utilizzi.

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2007
    Messaggi
    196
    questo è il mio script x upload :






    <%
    'Sample file Field-SaveAs.asp
    'Store extra upload info to a database
    ' and file contents to the disk
    Server.ScriptTimeout = 5000

    'Create upload form
    'Using Huge-ASP file upload
    'Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")
    'Using Pure-ASP file upload
    Dim Form: Set Form = New ASPForm %><%


    Server.ScriptTimeout = 1000
    Form.SizeLimit = &HA00000'10MB

    'was the Form successfully received?
    Const fsCompletted = 0

    If Form.State = fsCompletted Then 'Completted

    'Create destination path+filename for the source file.
    Dim DestinationPath, DestinationFileName
    DestinationPath = Server.mapPath("public\images")
    DestinationFileName = DestinationPath & "\" & str_users_code & "\" & Form("SourceFile").FileName


    'Open recordset to store uploaded data
    Dim RS: Set RS = OpenUploadRS

    'Store extra info about upload to database
    RS.AddNew
    RS("UploadDT") = Now()
    RS("Description") = Form.Texts.Item("Description")
    RS("SourceFileName") = Form("SourceFile").FilePath
    RS("DestFileName") = DestinationFileName
    RS("DataSize") = Form("SourceFile").Length

    RS("name") = str_users_name
    RS("code") = str_users_code
    '...
    RS.Update

    Response.write "
    Source file names:"
    Dim Field: For Each Field in Form.Files.Items
    Response.write "
    " & Field.FileName
    Next
    '{b}Save file to the destination
    Form("SourceFile").SaveAs DestinationFileName
    '{/b}

    'response.write "<Font color=green>
    SourceFile was saved as " & DestinationFileName )
    'response.write "
    See ListFiles table in " & Server.MapPath("mdb-database\utenti.mdb") & " database.</Font>"
    Response.Redirect("fotoprofilo.asp")

    ElseIf Form.State > 10 then
    Const fsSizeLimit = &HD
    Select case Form.State
    case fsSizeLimit: response.write "
    <Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font>
    "
    case else response.write "
    <Font Color=red>Some form error.</Font>
    "
    end Select
    End If'Form.State = 0 then

    Function OpenUploadRS()
    Dim RS : Set RS = CreateObject("ADODB.Recordset")

    'Open dynamic recordset, table Upload
    RS.Open "ListFiles", GetConnection, 2, 2

    Set OpenUploadRS = RS
    end Function

    Function GetConnection()
    dim Conn: Set Conn = CreateObject("ADODB.Connection")
    Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
    Conn.open "Data Source=" & Server.MapPath("mdb-database\utenti.mdb")
    set GetConnection = Conn
    end function

    %>

    <head>
    <title><%=pageTitle%> .::. <%=str_users_name%> .::.</title>
    <LINK href="css/file.css" type=text/css rel=stylesheet>

    <meta name="title" content="Mega Community">
    <meta name="description" content="Benvenuto nella Community dei ragazzi. Avrai la possibilità di inserire foto e blog personali. Entra per conoscere gente nuova ! megacommunity.it">
    <meta name="keywords" content="megacommunity megacommunity.it chat forum foto album classifiche community ragazzi ragazze cazzate blog discussioni ">
    <meta name="author" content="Walter Benetello">
    <meta name="copyright" content="Walter Benetello Copyright @ 2007">
    <meta http-equiv="Reply-to" content="walter.benetello@gmail.com">
    <meta http-equiv="content-language" content="IT">
    <meta http-equiv="Content-Type" content="text/html; iso-8859-1">
    <meta name="ROBOTS" content="INDEX,FOLLOW">

    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }

    function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }

    function MM_findObj(n, d) { //v4.01
    var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

    function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
    //-->
    </script>
    <script type="text/javascript" language="JavaScript" src="http://www.megacommunity.it/myasg/stats_js.asp"></script>
    </head>

    <body background="back_all.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" lang="it" onLoad="MM_preloadImages('bottoni/iscritti2.gif','bottoni/classifiche2.png','bottoni/album2.gif','bottoni/blog2.gif','bottoni/links2.gif','bottoni/newsletters2.gif','bottoni/cazzate2.gif','bottoni/muretto2.gif','bottoni/discussioni2.gif','bottoni/home2.gif')">
    <div align="center">
    <table width="998" background="sfondo2.gif" border="0">

    <tr>
    <td colspan="3" rowspan="2" valign="top"></td>
    <td width="25" height="118" valign="top"></td>
    <td colspan="2" valign="top">[img]bottoni/home.gif[/img]</td>
    <td width="61" valign="top"></td>
    <td colspan="2" valign="top">[img]bottoni/iscritti.gif[/img]</td>
    <td colspan="2" valign="top"></td>
    <td colspan="3" valign="top">[img]bottoni/classifiche.png[/img]</td>
    <td colspan="3" valign="top"></td>
    <td width="1"></td>
    </tr>
    <tr>
    <td colspan="12" rowspan="2" valign="top" align="center" bordercolor="#FFFFFF" style="border-style: dotted; border-width: 1px">[img]bottoni/profilo.gif[/img]<font size="+3"><sup><%=str_users_name%></sup></font></td>

    <td colspan="2" rowspan="3" valign="top"></td>
    <td height="30"></td>
    </tr>
    <tr>
    <td colspan="3" rowspan="3" valign="top">[img]bottoni/album.gif[/img]</td>
    <td height="16"></td>
    </tr>
    <tr>
    <td colspan="12" rowspan="6" valign="top">
    <div style="position: relative; width: 100%; height: 80%; z-index: 1; " id="livello2">
    <table width="100%" border="1">
    <form method=post ENCTYPE="multipart/form-data">

    <tr>
    <td width="347" height="23" valign="top">Scegli la foto da inserire

    (solo formato .JPG e .GIF e non piu di 300Kb di peso) </td>
    <td width="150" valign="top"><input type="file" name="SourceFile" size="40"></td>
    </tr>
    <tr>
    <td height="42" valign="top">Descrizione Foto :</td>
    <td valign="top">
    <textarea cols="60" rows="5" name="Description"></textarea>
    </td>
    </tr>
    <tr>
    <td height="23" valign="top"></td>
    <td valign="top" align="right"><input type="submit" Name="Action" value="Upload the file &gt;&gt;"></td>
    </tr>
    </form>
    </table>
    </div>
    </td>
    <td height="26"></td>
    </tr>
    <tr>
    <td colspan="2" rowspan="2" valign="top">[img]bottoni/muretto.gif[/img]</td>
    <td height="55"></td>
    </tr>
    <tr>
    <td colspan="3" rowspan="2" valign="top"></td>
    <td height="33"></td>
    </tr>
    <tr>
    <td colspan="2" rowspan="2" valign="top"></td>
    <td height="25"></td>
    </tr>
    <tr>
    <td colspan="2" rowspan="2" valign="top">[img]bottoni/blog.gif[/img]</td>
    <td width="2" rowspan="2" valign="top"></td>
    <td height="51"></td>
    </tr>
    <tr>
    <td colspan="2" rowspan="2" valign="top">[img]bottoni/cazzate.gif[/img]</td>
    <td height="42"></td>
    </tr>
    <tr>
    <td colspan="3" rowspan="2" valign="top"></td>
    <td colspan="5" rowspan="2" valign="top">[img]bottoni\logout2.gif[/img][img]bottoni\torna.gif[/img]</td>
    <td colspan="7" rowspan="2" align="right" valign="top"></td>
    <td height="46"></td>
    </tr>
    <tr>
    <td colspan="2" rowspan="2" valign="top"></td>
    <td height="36"></td>
    </tr>
    <tr>
    <td width="1" rowspan="2" valign="top"></td>
    <td colspan="4" rowspan="3" valign="top">[img]bottoni/discussioni.gif[/img]</td>
    <td width="149" rowspan="3" valign="top"></td>
    <td colspan="2" rowspan="3" valign="top">[img]bottoni/newsletters.gif[/img]</td>
    <td colspan="2" rowspan="3" valign="top"></td>
    <td colspan="2" rowspan="3" valign="top">[img]bottoni/links.gif[/img]</td>
    <td height="36" colspan="3" valign="top"></td>
    <td></td>
    </tr>
    <tr>
    <td width="174" rowspan="2" valign="top"></td>
    <td colspan="3" rowspan="2" valign="top"></td>
    <td width="19" rowspan="2" valign="top"></td>
    <td height="59"></td>
    </tr>
    <tr>
    <td height="7"></td>
    <td></td>
    </tr>
    <tr>
    <td height="27" colspan="17" valign="top" align="center">
    <% Server.Execute("footer.asp") %>
    </td>
    <td></td>
    </tr>
    <tr>
    <td height="5"></td>
    <td width="104"></td>
    <td></td>
    <td></td>
    <td width="19"></td>
    <td></td>
    <td></td>
    <td width="142"></td>
    <td width="1"></td>
    <td width="1"></td>
    <td width="101"></td>
    <td width="2"></td>
    <td></td>
    <td width="1"></td>
    <td width="1"></td>
    <td width="105"></td>
    <td></td>
    <td></td>
    </tr>
    </table>
    </div>
    </body>

  4. #4
    non ho dato una letta approfondota al tuo script comunque basta che controlli le 3 lettere e se sono gif, jpg, tif.... o comunque estensioni di immagini gli stampi un'errore.
    in paratica:
    codice:
    arrname=split(File.Name,".")
    if arrname(1)="gif" or if arrname(1)="jpg" ... qui metti tutte le estensioni ... then
      responselwrite "ERRORE N° : non è possibile fare l'upload di immagini"
    else
      qui metti tutto l'upload
    end if
    ...Se avanzo seguitemi... Se indietreggio uccidetemi...
    BiteFight... arruolati con me e non te ne pentirai

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2007
    Messaggi
    196
    non va .. ma al posto di file.name cosa devo mettere ?

  6. #6
    Utente di HTML.it
    Registrato dal
    Jul 2007
    Messaggi
    196
    ok andato.. funziona ora..


    ma invece di response.write si puo mettere un allarme tipo alert ???

  7. #7
    si però quella è una cosa che va fatta in java... cerca alert su google io ora non mi ricordo esattamente come sia...
    ...Se avanzo seguitemi... Se indietreggio uccidetemi...
    BiteFight... arruolati con me e non te ne pentirai

  8. #8
    Utente di HTML.it
    Registrato dal
    Jul 2007
    Messaggi
    196
    fatto fatto ! grazie...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.