Показать сообщение отдельно

  #7  
Старый 14.12.2007, 00:18
groundhog
Познавший АНТИЧАТ
Регистрация: 12.05.2007
Сообщений: 1,235
Провел на форуме:
2238549

Репутация: 1318


Отправить сообщение для groundhog с помощью ICQ
По умолчанию

Форма mass_sender.html

Код:
<html>
   <head>
      <title>Lee Roy's Mass Sender. Greetz to DaMaGeLaB.</title>
      <style>
         * {
            font-family: Tahoma;
         }
      </style>
      <script>
         function create_form () {
            var ref = document.getElementById('upload_url').value;
            var files_num = document.getElementById('files_num').value;

            if (isNaN(files_num)) {
               alert('Wrong data entered!');
               return;
            }

            if (files_num <= 0) {
               alert('Value must be positive!');
               return;
            }

            document.getElementById('sender').action = ref;

            form_text = '';
            for (i = 0; i < files_num; i++) {
               form_text += '<input style="margin-bottom: 5px" type="file" name="file' + i + '" size="70">';
            }

            document.getElementById('container').innerHTML = form_text;
         }

         function submit_func() {
            document.getElementById('sender').submit();
         }
      </script>
   </head>
   <body>
      <center>
         <h3>How many files do you want to upload?</h3>
         <input id="files_num" type="text" size="10" value="0">
         <h3>What URL do you want to use as upload script?</h3>
         <input id="upload_url" type="text" size="50" value="http://www.somesite.ru/dir/upload.php">
         <br><br>
         <input type="button" value="Create form" onclick="create_form()">
         <hr style="margin-top: 15px; margin-bottom: 15px">
         <form id="sender" method="post" enctype="multipart/form-data">
            <div id="container">
               <small>Enter apropriate number of files you want to send, and press <b>"Create form"</b> button...</small>
            </div>
         </form>
         <hr>
         <input type="button" value="Send" onclick="submit_func()">
      </center>
   </body>
</html>
Скрипт загрузки файлов:

PHP код:
<?php

define
("SERVER_UPLOAD_DIR""/home/bukerru/upload");

set_time_limit(0);

if (isset(
$_FILES) && is_array($_FILES)) {
   foreach (
$_FILES as $file) {
      if (
$file['error'] == 0) {
         
$destination sprintf("%s/%s"SERVER_UPLOAD_DIR$file['name']);
         if (@
move_uploaded_file($file['tmp_name'], $destination))
            
printf("File '%s' with size %s Kb was successfully uploaded...<br>\n"$file['name'], round($file[size] / 10242));
         else
            
printf("Could not move uploaded file '%s' to destination...");
      } else
         
printf("Error %s occuried. Could not upload file to server - skiping..."$file['error']);
   }
} else {
   
printf("No files was uploaded!");
}

?>
Не забудь создать директорию "/home/bukerru/upload". По идее ругаться ни на что не должен. Форма поддерживает загрузку нескольких файлов, разумеется, количество файлов нужно выбирать исходя из широты своего канала...