Accueil > Forum > > > > UPLOAD des fichiers pdf d'un poste client vers un serveur en asp
UPLOAD des fichiers pdf d'un poste client vers un serveur en asp
mardi 27 juillet 2010 à 17:19:14 |
UPLOAD des fichiers pdf d'un poste client vers un serveur en asp

madhatterx
|
Bonjour,
J'ai trouvé plusieurs codes pour "uploader" des fichiers d'un client vers un serveur en ASP, j'ai fait ma cuisine avec tout ça et j'obtiens le code suivant:
-1ere étape:
transfert.asp
Code HTML :
<%@ LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Transfert de fichier</title>
<link rel="stylesheet" type="text/css" href="http://10.0.0.241/itcinfo/feusty.css">
</head>
<body>
<p align="center" style="margin-top: 0; margin-bottom: 0"><b><font size="2" color="#0000FF">TRANSFERT DE FICHIER</font></b></p>
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="upload.asp">
<TABLE align="center">
<tr><td><b>Sélectionnez un fichier à transférer:</b><br><INPUT TYPE=FILE SIZE=50 NAME="FILE1"></td></tr>
<tr><td align="center"><INPUT TYPE=SUBMIT VALUE="Transférer"></td></tr>
</TABLE>
</FORM>
</body></HTML>
-2eme étape:
upload.asp
Code ASP :
<%@ Language=VBScript %>
<html>
<head>
<title>Transfert de fichier</title>
<link rel="stylesheet" type="text/css" href="http://10.0.0.241/itcinfo/feusty.css">
</head>
<body>
<%
Class FileUploader
Public Files
Private mcolFormElem
Private Sub Class_Initialize()
Set Files = Server.CreateObject("Scripting.Dictionary")
Set mcolFormElem = Server.CreateObject("Scripting.Dictionary")
End Sub
Private Sub Class_Terminate()
If IsObject(Files) Then
Files.RemoveAll()
Set Files = Nothing
End If
If IsObject(mcolFormElem) Then
mcolFormElem.RemoveAll()
Set mcolFormElem = Nothing
End If
End Sub
Public Property Get Form(sIndex)
Form = ""
If mcolFormElem.Exists(LCase(sIndex)) Then Form = mcolFormElem.Item(LCase(sIndex))
End Property
Public Default Sub Upload()
Dim biData, sInputName
Dim nPosBegin, nPosEnd, nPos, vDataBounds, nDataBoundPos
Dim nPosFile, nPosBound
biData = Request.BinaryRead(Request.TotalBytes)
nPosBegin = 1
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
If (nPosEnd-nPosBegin) <= 0 Then Exit Sub
vDataBounds = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
nDataBoundPos = InstrB(1, biData, vDataBounds)
Do Until nDataBoundPos = InstrB(biData, vDataBounds & CByteString("--"))
nPos = InstrB(nDataBoundPos, biData, CByteString("Content-Disposition"))
nPos = InstrB(nPos, biData, CByteString("name="))
nPosBegin = nPos + 6
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
sInputName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
nPosFile = InstrB(nDataBoundPos, biData, CByteString("filename="))
nPosBound = InstrB(nPosEnd, biData, vDataBounds)
If nPosFile <> 0 And nPosFile < nPosBound Then
Dim oUploadFile, sFileName
Set oUploadFile = New UploadedFile
nPosBegin = nPosFile + 10
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
sFileName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
oUploadFile.FileName = Right(sFileName, Len(sFileName)-InStrRev(sFileName, "\"))
nPos = InstrB(nPosEnd, biData, CByteString("Content-Type:"))
nPosBegin = nPos + 14
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
oUploadFile.ContentType = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
nPosBegin = nPosEnd+4
nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
oUploadFile.FileData = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
If oUploadFile.FileSize > 0 Then Files.Add LCase(sInputName), oUploadFile
Else
nPos = InstrB(nPos, biData, CByteString(Chr(13)))
nPosBegin = nPos + 4
nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
If Not mcolFormElem.Exists(LCase(sInputName)) Then mcolFormElem.Add LCase(sInputName), CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
End If
nDataBoundPos = InstrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)
Loop
End Sub
'String to byte string conversion
Private Function CByteString(sString)
Dim nIndex
For nIndex = 1 to Len(sString)
CByteString = CByteString & ChrB(AscB(Mid(sString,nIndex,1)))
Next
End Function
'Byte string to string conversion
Private Function CWideString(bsString)
Dim nIndex
CWideString =""
For nIndex = 1 to LenB(bsString)
CWideString = CWideString & Chr(AscB(MidB(bsString,nIndex,1)))
Next
End Function
End Class
Class UploadedFile
Public ContentType
Public FileName
Public FileData
Public Property Get FileSize()
FileSize = LenB(FileData)
End Property
Public Sub SaveToDisk(sPath)
Dim oFS, oFile
Dim nIndex
If sPath = "" Or FileName = "" Then Exit Sub
If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
If Not oFS.FolderExists(sPath) Then Exit Sub
Set oFile = oFS.CreateTextFile(sPath & FileName, True)
For nIndex = 1 to LenB(FileData)
oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
Next
oFile.Close
End Sub
Public Sub SaveToDatabase(ByRef oField)
If LenB(FileData) = 0 Then Exit Sub
If IsObject(oField) Then
oField.AppendChunk FileData
End If
End Sub
End Class
' Create the FileUploader
Dim Uploader, File
Set Uploader = New FileUploader
' This starts the upload process
Uploader.Upload()
' Check if any files were uploaded
If Uploader.Files.Count = 0 Then
Response.Write "Fichier non transféré."
Else
Response.Write "<b>Transfert terminé avec succès! </b><br>"
' Loop through the uploaded files
For Each File In Uploader.Files.Items
' Save the file
File.SaveToDisk "C:\inetpub\wwwroot\itcinfo\References\PDF"
' Output the file details to the browser
Response.Write "Fichier transféré: " & File.FileName & "<br>"
Response.Write "Taille: " & File.FileSize & " bits<br>"
Response.Write "Type: " & File.ContentType & "<br><br>"
Next
End If
%>
</body></HTML>
Du poste client, j'arrive à uploader des fichiers ".asp", word, excel, access, ".png", ".jpeg", ".gif", ".zip", ".bmp", MAIS je n'arrive pas à transférer les fichiers de type ".txt", ".pdf", ".wma" ... le PDF étant le plus important pour mon appli.
Merci de me donner un coup de pouce.
|
|
mardi 27 juillet 2010 à 17:50:16 |
Re : UPLOAD des fichiers pdf d'un poste client vers un serveur en asp

PascalCmoa
|
Bonjour,
Pourquoi ne pas avoir fait quelque chose comme ci-dessous, ce bout de code fonctionne parfaitement:
Code ASP.NET :
...
<div align="left" style="padding: 10px 10px 10px 10px;">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<legend>
<asp:Label ID="lblTitreZoneFichier" runat="server" CssClass="spanTexte" Text="Téléchargement des fichiers:"></asp:Label></legend>
<table border="0" cellpadding="1" cellspacing="1" width="700">
<tr>
<td style="width: 150px">
<asp:Label ID="lblNomFichier" runat="server" Text="Nom fichier:" CssClass="spanTexte"
Width="100%"></asp:Label></td>
<td>
<asp:FileUpload ID="FindFile" runat="server" Width="500px" /></td>
<td align="center" style="width: 103px">
<asp:Button ID="btnAjoutFichier" runat="server" Height="23px" Width="100px" Text="Ajouter"
CssClass="spanTexte" /></td>
</tr>
<tr>
<td colspan="2">
<asp:ListBox ID="lstFiles" runat="server" Height="100px" Width="500px" CssClass="spanTexte">
</asp:ListBox></td>
<td align="center" style="width: 103px">
<asp:Button ID="btnSupprimeFichier" runat="server" CssClass="spanTexte" Height="23px"
Text="Supprimer" Width="100px" /></td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblMessage" runat="server" Height="25px" Width="100%" CssClass="spanTexte"></asp:Label></td>
<td align="center" style="width: 103px">
<asp:Button ID="btnUpload" runat="server" CssClass="spanTexte" Text="Uploader" Width="100px" /></td>
</tr>
<tr>
<td align="center" colspan="3">
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:Label ID="lblEncoursTraitement" runat="server" Text="En cours de traitement ..."></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/ajax-loader.gif" /></td>
</tr>
</table>
</ProgressTemplate>
</asp:UpdateProgress>
</td>
</tr>
</table>
<br />
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnUpload" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnAjoutFichier" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnSupprimeFichier" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
...
Code Visual Basic :
...
Protected Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
Dim status As String = ""
lblMessage.Text = ""
Dim fileOK As Boolean = False
If lstFiles.Items.Count = 0 And filesUploaded = 0 Then
lblMessage.Text = "Erreur un nom de fichier doit etre spécicié."
Exit Sub
Else
For fic As Integer = 0 To hif.Count - 1
If CType(hif.Item(fic), FileUpload).HasFile Then
Dim fileExtension As String = System.IO.Path.GetExtension(hif.Item(fic).PostedFile.FileName).ToLower()
Dim allowedExtensions As String() = {".jpg", ".jpeg", ".png", ".gif", ".pdf"}
For i As Integer = 0 To allowedExtensions.Length - 1
If fileExtension = allowedExtensions(i) Then
fileOK = True
End If
Next
If fileOK Then
Try
Dim iFile As FileInfo
iFile = New FileInfo(baseLocation & System.IO.Path.GetFileName(hif.Item(fic).PostedFile.FileName))
If iFile.Exists Then
lblMessage.Text &= "Le fichier " & System.IO.Path.GetFileName(hif.Item(fic).PostedFile.FileName) & " est déjà présent.<br />"
Else
CType(hif.Item(fic), FileUpload).PostedFile.SaveAs(baseLocation & System.IO.Path.GetFileName(hif.Item(fic).PostedFile.FileName))
filesUploaded += 1
End If
Catch ex As Exception
lblMessage.Text = "Erreur de sauvegarde du fichier " & System.IO.Path.GetFileName(hif.Item(fic).PostedFile.FileName) & "<br />" & ex.Message
End Try
End If
End If
Next fic
If filesUploaded > 1 Then
lblMessage.Text &= "Les " & filesUploaded & " fichiers ont été uploadés avec succès." + status
Else
lblMessage.Text &= "Le fichier a été uploadé." + status
End If
filesUploaded = 0
hif.Clear()
lstFiles.Items.Clear()
End If
End Sub
...
PascalCmoa
email: PascalCmoa
|
|
mercredi 28 juillet 2010 à 08:00:45 |
Re : UPLOAD des fichiers pdf d'un poste client vers un serveur en asp

madhatterx
|
Merci d'avoir répondu si vite! :)
Le problème, c'est que mon appli est pour un Intranet tout en ASP, et je ne connais pas encore ASP.NET.
Je vais essayer quand même avec ton code.
|
|
mercredi 28 juillet 2010 à 08:18:30 |
Re : UPLOAD des fichiers pdf d'un poste client vers un serveur en asp

madhatterx
|
indications supplémentaires:
je bosse sur windows server 2008, avec IIS7 et SQL Server 2008.
Si ça peut faire avancer le schmilblick. 
|
|
mercredi 28 juillet 2010 à 14:06:37 |
Re : UPLOAD des fichiers pdf d'un poste client vers un serveur en asp

madhatterx
|
Je n'ai pas réussi à paramétrer ton code pour mon appli
Aurais-tu une variante en ASP classic? stp
|
|
Cette discussion est classée dans : end, spath, nindex, if, then
Répondre à ce message
Livres en rapport
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
STABILITé DU DéBIT 3GSTABILITé DU DéBIT 3G par benzekrighizlane
Cliquez pour lire la suite par benzekrighizlane
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|