[JS] multible upload via 1 file-selectbox

Pagina: 1
Acties:

  • BobDay
  • Registratie: December 2001
  • Laatst online: 11-08-2025
Met welke technieken krijg ik het voor elkaar om ism php bestanden te uploaden voor mijn cms-systeem op de wijze zoals het ook gedaan wordt in onderstaande afbeelding.

http://members.lycos.co.uk/bodday/multibleupload.gif
[understatement]van de bron-code in bovenstaande formulier word ik niet gelukkig :X [/understatement]

Het probleem is namelijk dat <input type="file" value="dit niet wordt toegestaan">

Met het schrijven van het script red ik mij wel, ik heb dus alleen een strategie nodig hoe dit probleem aan te pakken.

43% of all statistics are worthless


  • sjroorda
  • Registratie: December 2001
  • Laatst online: 18:13
Wordt het op jouw voorbeeld niet gedaan door elke file stuk voor stuk te uploaden, die in een tijdelijke dir te zetten, en dan te versturen? Of wordt alles pas geupload nadat je op 'send' klikt?

  • BobDay
  • Registratie: December 2001
  • Laatst online: 11-08-2025
alles wordt geupload nadat op send is geklikt.

[ Voor 8% gewijzigd door BobDay op 16-04-2003 09:27 ]

43% of all statistics are worthless


  • sjroorda
  • Registratie: December 2001
  • Laatst online: 18:13
Dan zou een mogelijkheid kunnen zijn dat naast de 'gewone' zichtbare file-input andere file-inputs op de pagina staan die m.b.v. CSS onzichtbaar zijn gemaakt?

  • Pelle
  • Registratie: Januari 2001
  • Laatst online: 09:52

Pelle

🚴‍♂️

Ik denk dat nadat er op 'add' geklikt wordt, die layer onzichtbaar gemaakt wordt en er een nieuwe verschijnt met een lege input type="file". De value wordt vervolgens naar die text-area geschreven.

Verwijderd

Ik denk dat het bestand bij elke klik op "Add to list" geupload wordt. De lijst (plaatje 1 en plaatje 2) geeft aan welke attachments er in de temp-directory op de server staan (zo doet hotmail het iig wel).

Maar de manier van Pelle is natuurlijk veel mooier, zou moeten kunnen werken...

  • BobDay
  • Registratie: December 2001
  • Laatst online: 11-08-2025
Doekman, in mijn tweede reactie had ik al vermeld dat het uploaden na het versturen pas wordt gedaan.
De manier zoals Pelle aandraagt ben ik nu aan het maken

43% of all statistics are worthless


Verwijderd

BobDay, je heb helemaal gelijk, 'was niet erg constructief. Lezen is moeilijk. |:(

Verwijderd

Het staat me bij dat als je de file input visibility:hidden of display:none maakt dat het bestand niet wordt geupload. Wat je dan nog altijd kunt doen (dat werkt iig):

JavaScript:
1
<input type="file" style="filter:alpha(opacity=0);" />

  • Pelle
  • Registratie: Januari 2001
  • Laatst online: 09:52

Pelle

🚴‍♂️

Is dat zo? Ik zou 'm persoonlijk in een divje gooien overigens, en die op display: none zetten, in plaats van van input zelf.

  • BobDay
  • Registratie: December 2001
  • Laatst online: 11-08-2025
oei, nuttige info!
Ik denk en hoop dat de Pelle manier nog steeds werkt. Ik blijf nog even scripten en kan het dan testen.

43% of all statistics are worthless


Verwijderd

Probeer dit maar eens ;)

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">




<html>
<head>
    <title>Untitled</title>
</head>

<body>




<style>
.myFileSelection {
 font-family:arial;
 font-size:12px;
 width:480px;
 height:160px;
 margin:0px;
 padding:0px;
}

body {
 background-color:buttonface;
 padding:2px;
 margin-left:20px;
 margin-top:0px;
 margin-bottom:0px;
 margin-right:0px;
}

.submitButton {
 height:22px;
}

.buttonOff {
 border:1px solid buttonface;
 cursor:hand;
}

.buttonOn {
  border-left:1px solid white;
  border-top:1px solid white;
  border-right:1px solid #848284;
  border-bottom:1px solid #848284;
  cursor:hand;
}

.menuBar {


}

.buttonPressed {
  border-left:1px solid #848284;
  border-top:1px solid #848284;
  border-right:1px solid white;
  border-bottom:1px solid white;
  padding-left:1px;
  padding-top:1px;
  cursor:hand;
}

.message {
 font-family:arial;
 font-size:11px;
} 

.legend {
 font-family:arial;
 font-size:12px;
}

.fieldset {
 padding-left:7px;
}
</style>

<script>

var ffCount=2;

function swapInSwapOut(theEl) 
{
 var proceed=true;
  //Check for duplicate entry
 var toSearch=document.getElementById("fileField"+theEl).value;
 
 for(i=0;i<document.myFileList.myFiles.options.length;i++) {
  if(document.myFileList.myFiles.options[i].text==toSearch) {
   alert("That file is already in the Upload List");
   proceed=false;
   break;
  }
 }
 
 if(proceed) {
 document.getElementById("uploadButton").disabled=false;
 var newOption = document.createElement("OPTION");
 document.getElementById("myFiles").options.add(newOption);
 newOption.innerText = document.getElementById("fileField"+theEl).value;
 newOption.value = theEl;
 document.myFileList.myFiles.selectedIndex=newOption.index;
 document.myFileList.myFiles.focus();
 
 insertFileBox();
 
  var selectedList="";
  for(i=0;i<document.myFileList.myFiles.options.length;i++)
  {
    if(document.myFileList.myFiles.options[i]!=null) {
    selectedList+=document.myFileList.myFiles.options[i].value + ",";
    }
  }
  document.getElementById("formFFCount").value=selectedList;
 
 ffCount++;
 }
}

function insertFileBox()
{
 var newType="<input type=\"file\" id=\"fileField"+ffCount+"\" onchange=\"swapInSwapOut(" + ffCount + ")\" name=\"fileField"+ffCount+"\">";
 var newFileInput=document.createElement(newType);
 document.myFileList.insertAdjacentElement("AfterBegin",newFileInput);
 document.getElementById("fileField"+ffCount).style.position="absolute"; 
 document.getElementById("fileField"+ffCount).style.top="209px"; 
 document.getElementById("fileField"+ffCount).style.left="310px"; 
 document.getElementById("fileField"+ffCount).style.width="30px"; 
 document.getElementById("fileField"+ffCount).style.zIndex=ffCount; 
 document.getElementById("hider").style.zIndex=ffCount+1;
}

function submitData() {
 document.getElementById("uploadButton").disabled=true;
 document.myFileList.submit();
}

function removeOptionsByValue(selectName, value) {
  for (var i=selectName.options.length-1; i>=0; i--) {
    if (selectName.options[i].value == value) {
      selectName.options[i] = null;
    }
  }
}

function removeFile() {
 
  var selectedList="";
  for(i=0;i<document.myFileList.myFiles.options.length;i++)
  {
   if(document.myFileList.myFiles.options[i].selected==true) {
    selectedList+=document.myFileList.myFiles.options[i].value + ",";
   }
  }
  
  var splitList=selectedList.split(",");
  
  for(i=0;i<splitList.length-1;i++) {
   document.getElementById("fileField"+splitList[i]).disabled=true;
   removeOptionsByValue(document.myFileList.myFiles,splitList[i]);
  }
  
  var selectedList="";
  for(i=0;i<document.myFileList.myFiles.options.length;i++)
  {
    selectedList+=document.myFileList.myFiles.options[i].value + ",";
  }
  
  if(selectedList.length==0) {
   document.getElementById("uploadButton").disabled=true;
  }
  document.getElementById("formFFCount").value=selectedList;
  document.myFileList.myFiles.selectedIndex=0;
}

function keyPressed() {
 if(event.keyCode==46 || event.keyCode==8) {
  removeFile();
  event.cancelBubble=true;
  event.returnValue=0;
 }
}
</script>

<form name="myFileList" method="post" enctype="multipart/form-data" action="multiUpload.cfm">
<table cellspacing=0 cellpadding=0 height=220 width=500 align=center>
 <tr>
  <td height=20 colspan=2 class="menuBar"> 
   
   <table cellspacing=0 cellpadding=0 border=0>
   <tr>
    <td class="buttonOff" width=20 align=center valign=middle onclick="removeFile()" height=20 onmousedown="this.className='buttonPressed'" onmouseover="this.className='buttonOn'" onmouseout="this.className='buttonOff'">[img]"deleteIcon.gif"[/img]</td>
   </tr>
   </table>
   
  </td>
 </tr>
 <tr>
  <td colspan=2>
   <fieldset class="fieldset"><legend class="legend">To add a file to the upload list, click <b>Browse...</b></legend>
   <select name="myFiles" onkeydown="keyPressed()" id="myFiles" multiple class="myFileSelection"></select></fieldset>
  </td>
 </tr>
 <tr>
  <td align=left style="padding-top:10px;"><input type="button" value="Cancel" class="submitButton" onclick="window.close()"></td>
  <td align=right height=20 style="padding-top:10px;">
   <input type="hidden" value="0" id="formFFCount" name="formFFCount">
   <input type="hidden" value="" id="folder" name="folder">
   <input type="hidden" value="5CC7ACF0A7" id="uid" name="uid">
   <input type="file" id="fileField1" onchange="swapInSwapOut('1')" name="fileField1" style="width:30px;zIndex:1;position:absolute;top:209px;left:310px" value="Add File">
   <input type="button" default disabled id="uploadButton" value="Upload Files" class="submitButton" onclick="submitData()">
  </td>
 </tr></form>
</table>


<div id="hider" style="position:absolute;width:10px;height:23px;background-color:buttonface;top:209px;left:304px;zIndex:1000;"></div>


</body>
</html>

Verwijderd

Ik heb het even getest, maar het is gelukkig niet zo :) Ik had het per ongeluk verwisseld met wat anders |:(

Werkt mooi Gordijnstok!

  • BobDay
  • Registratie: December 2001
  • Laatst online: 11-08-2025
Verwijderd schreef op 16 April 2003 @ 18:25:
Probeer dit maar eens ;)

code:
1
...heel veel mooie code
woei, Gordijnstok had je dit toevallig liggen of ben jij even heel druk geweest?
In beide gevallen, vriendelijk bedankt! _/-\o_

Ik ga jouw script gebruiken, maar ga nog wel een kleine aanpassing maken: ik wil het script laten vragen om een korte beschrijving van de te uploaden files.

Jammer alleen dat mijn reeds geschreven code de prullenbak ik kan.

43% of all statistics are worthless

Pagina: 1