Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    upload img: A generic error occurred in GDI+.

    ciao a tutti,
    ho fatto una piccola area di amministrazione per i contenuti di un sito, tutto bene in locale. Online no, non mi carica le immagini.

    Ho l'hosting su Aruba ... ho letto in giro che alcuni hanno avuto lo stesso problema ma che per loro era un discorso di permessi. Ora, io cerco di fare l'upload nella cartella "public" che, se non sbaglio, ha i permessi di scrittura ... quindi?

    L'errore che mi da è questo:

    A generic error occurred in GDI+.

    Vi posto il codice

    codice:
    <%@ Page Trace="False" Language="vb" aspcompat="false" debug="true" validateRequest="false"%> 
    <%@ Import Namespace="System.Drawing" %>
    <%@ Import Namespace="System.Drawing.Imaging" %>
    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.Web" %>
    <script language="vbscript" runat="server">
        Const Lx = 200  ' max width for thumbnails
        Const Ly = 240  ' max height for thumbnails
        Const upload_dir = "../public/upload/"   ' directory to upload file
        Const upload_original = "sample"    ' filename to save original as (suffix added by script)
        Const upload_thumb = "thumb"    ' filename to save thumbnail as (suffix added by script)
        Const upload_max_size = 200 ' max size of the upload (KB) note: this doesn't override any server upload limits
        Dim fileExt ' used to store the file extension (saves finding it mulitple times)
        Dim newWidth, newHeight As Integer ' new width/height for the thumbnail
        Dim l2  ' temp variable used when calculating new size
        Dim fileFld As HttpPostedFile   ' used to grab the file upload from the form
        Dim originalimg As System.Drawing.Image ' used to hold the original image
        Dim msg ' display results
        Dim upload_ok As Boolean    ' did the upload work ?
    </script>
    <%
    randomize() ' used to help the cache-busting on the preview images
    upload_ok = false
    if lcase(Request.ServerVariables("REQUEST_METHOD"))="post" then
    	fileFld = request.files(0)	' get the first file uploaded from the form (note:- you can use this to itterate through more than one image)
    	if fileFld.ContentLength > upload_max_size * 1024 then
    		msg = "Sorry, the image must be less than " & upload_max_size & "Kb"
    	else
    	
                originalimg = System.Drawing.Image.FromStream(fileFld.InputStream)
                ' work out the width/height for the thumbnail. Preserve aspect ratio and honour max width/height
                ' Note: if the original is smaller than the thumbnail size it will be scaled up
                If (originalimg.Width / Lx) > (originalimg.Width / Ly) Then
                    l2 = originalimg.Width
                    newWidth = Lx
                    newHeight = originalimg.Height * (Lx / l2)
                    If newHeight > Ly Then
                        newWidth = newWidth * (Ly / newHeight)
                        newHeight = Ly
                    End If
                Else
                    l2 = originalimg.Height
                    newHeight = Ly
                    newWidth = originalimg.Width * (Ly / l2)
                    If newWidth > Lx Then
                        newHeight = newHeight * (Lx / newWidth)
                        newWidth = Lx
                    End If
                End If
    
                Dim thumb As New Bitmap(newWidth, newHeight)
    
                'Create a graphics object           
                Dim gr_dest As Graphics = Graphics.FromImage(thumb)
    
                ' just in case it's a transparent GIF force the bg to white 
                Dim sb = New SolidBrush(System.Drawing.Color.White)
                gr_dest.FillRectangle(sb, 0, 0, thumb.Width, thumb.Height)
    
                'Re-draw the image to the specified height and width
                gr_dest.DrawImage(originalimg, 0, 0, thumb.Width, thumb.Height)
    
    
                fileExt = System.IO.Path.GetExtension(fileFld.FileName).ToLower()
                originalimg.Save(Server.MapPath(upload_dir & upload_original & fileExt), originalimg.RawFormat)
                thumb.Save(Server.MapPath(upload_dir & upload_thumb & fileExt), originalimg.RawFormat)
                msg = "Uploaded " & fileFld.FileName & " to " & Server.MapPath(upload_dir & upload_original & fileExt)
                upload_ok = True
    
                ' Housekeeping for the generated thumbnail
                If Not thumb Is Nothing Then
                    thumb.Dispose()
                    thumb = Nothing
                End If
    
            End If
    
    	' House Keeping !
    	if not originalImg is nothing then
    		originalImg.Dispose()
    		originalImg = nothing
    	end if
    
    end if
    %>
    <html>
    <head>
    <title>ASP.NET File Upload and Resize Sample</title>
    <META NAME="Description" CONTENT="ASP.NET File Upload and Resize Sample (Hybrid VB.NET)">
    <META NAME="Keywords" CONTENT="ASP.NET, ASP, NET, VB, VBScript, Image, Upload, Resize, Thumbnail, Constrain, Filesize, File, Size, Free">
    <META NAME="Copyright" CONTENT="Rufan-Redi Pty Ltd 2005">
    <META NAME="Author" CONTENT="System developed by Jeremy at http://www.Rufan-Redi.com">
    </head>
    <body>
    
    <form enctype="multipart/form-data" method="post" runat="server">
    <table>
    <tr><td>Select the file to upload:</td><td><input type="file" name="upload_file"></td></tr>
    <tr><td colspan=2>Max upload size <%=upload_max_size%>Kb, gif/jpg/png only</td></tr>
    <tr><td colspan=2><input type="submit" value="Upload"></td></tr>
    </table>
    </form>
    
    <%
    if upload_ok then
    %>
    <table>
    <tr>
    <td valign=top>[img]<%=upload_dir & upload_original & fileExt & [/img]"></td>
    <td valign=top>[img]<%=upload_dir & upload_thumb & fileExt & [/img]"></td>
    </tr>
    </table>
    <%
    else
    	response.write(msg)
    end if
    %>
    
    </body>
    </html>
    aiuto plz!

  2. #2
    guest.1
    Guest
    ciao
    prova cosi:

    modifica questa riga:

    Const upload_dir = "../public/upload/" ' directory to upload file
    in

    Const upload_dir = "/public/upload/" ' directory to upload file


    ciao.

  3. #3
    niente, sempre lo stesso errore... grazie comunque.

    qualche altro suggerimento???


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.