Помощник
|
Определение типа файлов при выборе файла через input type="file" |
-=Jaga=-
|
Сообщение
#1
|
||
|
|
||
|
|||
Exterior |
26.5.2008, 10:28;
Ответить: Exterior
Сообщение
#2
|
|
-=Jaga=-, тут вот есть примерчик
|
|
|
-=Jaga=-
|
Сообщение
#3
|
|
Совсем запутался :), подскажите где там и что можно добавить в код приведенный мною?
|
|
|
Merlin_hb |
26.5.2008, 12:47;
Ответить: Merlin_hb
Сообщение
#4
|
|
Не повезло. Думаю что тип можно определить только на сервере.
The ENCTYPE property defines the Multipurpose Internet Mail Extensions (MIME) encoding for the form and must be set to "multipart/form-data" for file upload forms. When we set this property to "multipart/form-data" we obtain a different structure of the POST buffer (which is also more complex) and the Request ASP object can't access the form contents. Therefore, we can read the POST buffer using the Request.binaryRead method, but we can't use scripting languages to do this. The Request.binaryRead method returns a VTarray (which is a variant array of unsigned one byte characters) while scripting languages can manage only variant variables. We can resolve this problem only by using a specific, custom ASP component or ISAPI extension, such as CPSHOST.DLL. This behavior is by design. А вот если в форме то навеное юзать JavaScript придеться. |
|
|
Webmaster_hb |
26.5.2008, 20:27;
Ответить: Webmaster_hb
Сообщение
#5
|
|
-=Jaga=-, можно проверить тип файла до загрузки на сервер только через Javascript
для этого достаточно проверить имя файла и путь, он будет доступен после того как человек выбрал файл, и отсчитав последние четрые или пять символов сравнить их на равенство .html .rar .zip и т.п. примерно так <script>
var t=document.form_name.input_name.value; if(t!="") { var tmp=""; for(i=t.length-1;i>=0;i--) { tmp+=t.charAt(i); } var f=tmp.split("."); t=f[0].toLowerCase(); if((t.lastIndexOf("cod")==-1) && (t.lastIndexOf("fdp")==-1) && (t.lastIndexOf("slx")==-1) && (t.lastIndexOf("pmb")==-1) && (t.lastIndexOf("gpj")==-1) && (t.lastIndexOf("gepj")==-1)) { alert("Вы можете загрузить только DOC, PDF, XLS, BMP или JPEG файл."); } } </script> |
|
|
-=Jaga=-
|
Сообщение
#6
|
|
Спасибо! Буду пробовать подружиться с Java =)!
|
|
|
Exterior |
27.5.2008, 11:39;
Ответить: Exterior
Сообщение
#7
|
|
-=Jaga=-, только это не Java, а JavaScript - это разные весчи ;)
|
|
|
-=Jaga=-
|
Сообщение
#8
|
|
-=Jaga=-, только это не Java, а JavaScript - это разные весчи ;) Это я в курсе :rolleyes:, но только и всего :wacko:! Нашел в недрах сети следующий класс: <% '*************************************** ' File: Upload.asp ' Author: Jacob "Beezle" Gilley ' Email: [EMAIL="avis7@airmail.net"]avis7@airmail.net[/EMAIL] ' Date: 12/07/2000 ' Comments: The code for the Upload, CByteString, ' CWideString subroutines was originally ' written by Philippe Collignon...or so ' he claims. Also, I am not responsible ' for any ill effects this script may ' cause and provide this script "AS IS". ' Enjoy! '**************************************** 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 [COLOR=red]If sPath = "" Or FileName = "" Then Exit Sub 'ПЫТАЮСЬ ИЗМЕНИТЬ ЗДЕСЬ[/COLOR] msgbox FileName 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 %> If sPath = "" Or Rigth(FileName, 3) <> "doc" Then Exit Sub При таком варианте сервер ругается на Rigth. Это же стандартная функция VB. Может сначала загнать в переменную, а уже потом сравнивать? Попытался сделать так: Public Sub SaveToDisk(sPath) Dim oFS, oFile, rFile Dim nIndex Set rFile = Rigth(FileName, 3) If sPath = "" Or rFile <> "doc" Then Exit Sub При выполнении получаю ошибку 500. Помогай уважаемый All =)! Что я делаю не правильно? |
|
|
-=Jaga=-
|
Сообщение
#9
|
|
|
Все вопрос снят. В коде ошибки орфографическая и синтаксическая.
|
|
|
||
|
Похожие темы
Тема | Ответов | Автор | Просмотров | Последний ответ | |
---|---|---|---|---|---|
Bropush - Твой бро в монетизации через Push-уведомления | 28 | bropush | 11194 | Вчера, 12:52 автор: bropush |
|
Требуется помощь по сайту на "ВордПресс" Закрылся доступ в панель администратора |
12 | Tia2 | 1522 | 25.3.2024, 6:54 автор: Skyworker |
|
✅ sms.chekons.com - ⭐ Сервис для получения SMS на реальные номера USA "Non-VoIP, безлим SMS, API" ⭐ Сервис для получения SMS на реальные номера USA |
10 | Chekon | 3578 | 24.3.2024, 14:15 автор: Chekon |
|
⭐⭐⭐ Google Voice | Gmail - OLD аккаунты "SMS и звонки" ⭐⭐⭐ | 12 | Chekon | 3811 | 24.3.2024, 13:56 автор: Chekon |
|
Через какой браузер и как можно найти в кэшэ браузера видео | 10 | Room | 1929 | 23.3.2024, 7:41 автор: Room |
Текстовая версия | Сейчас: 28.3.2024, 20:05 |