powered by simpleCommunicator - 2.0.59     © 2025 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / HTML, JavaScript, VBScript, CSS [игнор отключен] [закрыт для гостей] / JS MULTY INPUT FILES
1 сообщений из 1, страница 1 из 1
JS MULTY INPUT FILES
    #39253153
KhafRAgur
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Есть скриптик, который загружает картинки на сервер, всё работает, но есть одна проблема. Так как это мультизагрузочный скрипт, то можно типа выбирать сразу несколько фалов для загрузки, по идее ещё можно удалять отобранные файлы, но ещё не отправленные на сервер.

Но чёто не выходит.. Нужно удалять нужный файл из массива files[] чтоб, если пользователь отменил его отправку, файл не загружался бы на сервер, но в данный момент, удалённый на странице файл, всё равно попадает на сервер при отправке.


<input type="file" id="files" name="files[]" multiple /> Наверно вот из этого массива, нужно как то удалить нужный файл..





//INDEX.PHP

Код: php
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.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<head>
<style>
	.thumb {height: 75px; border: 1px solid #000; margin: 10px 5px 0 0;}
</style>



<form method="post" target="a_IFrame" enctype="multipart/form-data" action="./upload.php">
	<input type="file" id="files" name="files[]" multiple   />
	<input type="submit" name="fil" id="fil" value="SEND" >
</form>

<iframe id="a_IFrame" name="a_IFrame" >--</iframe>

<div id="list"></div>


<script>
  function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object

    // Loop through the FileList and render image files as thumbnails.
     for (var i = 0, f; f = files[i]; i++) {

      // Only process image files.
      if (!f.type.match('image.*')) {
        continue;
      }

    var reader = new FileReader();

	var firsDiv=document.getElementsByTagName('span')[0];
	
	var files = [];

      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {
          // Render thumbnail.
          adArr(theFile.name);
          var span = document.createElement('span');
         // span.innerHTML = ['<img onclick=alert("', escape(theFile.name), '"),imgArr("', escape(theFile.name), '"); class="thumb" src="', e.target.result,
            span.innerHTML = ['<img id="', escape(theFile.name), '"  onclick=remove1("', escape(theFile.name), '"); class="thumb" src="', e.target.result,
                            '" title="', escape(theFile.name), '"/>'].join('');
          document.getElementById('list').insertBefore(span, firsDiv);
        };
      })(f);

      // Read in the image file as a data URL.
      reader.readAsDataURL(f);
    }
  }





card=[];

function remove1(id) 
{
	var elem = document.getElementById(id);
	elem.parentNode.removeChild(elem)

	if(card[0]==id){card.splice (0,1)}
	if(card[1]==id){card.splice (1,1)}
	if(card[2]==id){card.splice (2,2)}
	if(card[3]==id){card.splice (3,3)}

	arrList();
}




//INSERT IN ARRAY
function adArr(id) 
{
	if(card.length==0)
	{
		card[0] = id;
	} 
	else 
	{
		card[card.length] = id;
	} 
	
	arrList();
}



//ARRAY LIST
function arrList()
{
	if(card.length>4)
	{
		alert("LIMIT");
	}
	info.innerHTML =card[0]+card[1]+card[2]+card[3]+card[4];
}




//SEND
function send()
{
	var tempIFrame = document.createElement('iframe');
	// tempIFrame.setAttribute('id', 'a_IFrame');
	// tempIFrame.setAttribute('src','');
	document.getElementById('info').appendChild(tempIFrame);
}

document.getElementById('files').addEventListener('change', handleFileSelect, false);
  
</script>

<div id="info"></div>


</body>
</html>





//UPLOAD.PHP

Код: php
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.
<?php
  
   $uploaded = 0;
   $message = array();
  
   foreach ($_FILES['files']['name'] as $i => $name) {
       
        if ($_FILES['files']['error'][$i] == 4) {
            continue; 
        }
       
        if ($_FILES['files']['error'][$i] == 0) {
           
             if ($_FILES['files']['size'][$i] > 99439443) {
                $message[] = "$name exceeded file limit.";
                continue;  
             }
            

	move_uploaded_file($_FILES['files']['tmp_name'][$i], "./files/".$_FILES['files']['name'][$i]);
	chmod("./files/".$_FILES['files']['name'][$i], 0777);

            
             $uploaded++;
        }
   }
  
   echo $uploaded . ' files uploaded.';
  
   foreach ($message as $error) {
      echo $error;
   }

?> 
...
Рейтинг: 0 / 0
1 сообщений из 1, страница 1 из 1
Форумы / HTML, JavaScript, VBScript, CSS [игнор отключен] [закрыт для гостей] / JS MULTY INPUT FILES
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]