За последние 24 часа нас посетили 23243 программиста и 1700 роботов. Сейчас ищут 1645 программистов ...

не вкуриваю как получить данные

Тема в разделе "Вопросы от блондинок", создана пользователем TROODON, 11 апр 2008.

  1. TROODON

    TROODON Активный пользователь

    С нами с:
    4 ноя 2007
    Сообщения:
    112
    Симпатии:
    0
    нашёл один хтмл/яваскрипт пример по мульти аттачу поковырял но не понял ка написать к нему форму которая файлы принимать будет...

    помогите плиз

    example.html
    HTML:
    1.  
    2.     <!-- Include the javascript -->
    3.     <script src="multifile.js"></script>
    4. </head>
    5.  
    6.  
    7. <!-- This is the form -->
    8. <form enctype="multipart/form-data" action="1.php" method = "post">
    9.     <!-- The file element -- NOTE: it has an ID -->
    10.     <input id="my_file_element" type="file" name="file[]" >
    11.     <input type="submit">
    12. </form>
    13. Файлы:
    14. <!-- This is where the output will appear -->
    15. <div id="files_list"></div>
    16.     <!-- Create an instance of the multiSelector class, pass it the output target and the max number of files -->
    17.     var multi_selector = new MultiSelector( document.getElementById( 'files_list' ), 3 );
    18.     <!-- Pass in the file element -->
    19.     multi_selector.addElement( document.getElementById( 'my_file_element' ) );
    20. </body>
    21. </html>
    multifile.js
    [js]function MultiSelector( list_target, max ){
    this.list_target = list_target;
    this.count = 0;
    this.id = 0;
    if( max ){
    this.max = max;
    } else {
    this.max = -1;
    };
    this.addElement = function( element ){
    if( element.tagName == 'INPUT' && element.type == 'file' ){
    element.name = 'file[]';
    element.multi_selector = this;
    element.onchange = function(){
    var new_element = document.createElement( 'input' );
    new_element.type = 'file';
    new_element.name = 'file[]';
    this.parentNode.insertBefore( new_element, this );
    this.multi_selector.addElement( new_element );
    this.multi_selector.addListRow( this );
    this.style.position = 'absolute';
    this.style.left = '-1000px';
    };
    if( this.max != -1 && this.count >= this.max ){
    element.disabled = true;
    };
    this.count++;
    this.current_element = element;
    } else {
    alert( 'Error: not a file input element' );
    };
    };
    this.addListRow = function( element ){
    var new_row = document.createElement( 'div' );
    var new_row_button = document.createElement( 'input' );
    new_row_button.type = 'button';
    new_row_button.value = 'Delete';
    new_row.element = element;
    new_row_button.onclick= function(){
    this.parentNode.element.parentNode.removeChild( this.parentNode.element );
    this.parentNode.parentNode.removeChild( this.parentNode );
    this.parentNode.element.multi_selector.count--;
    this.parentNode.element.multi_selector.current_element.disabled = false;
    return false;
    };
    new_row.innerHTML = element.value;
    new_row.appendChild( new_row_button );
    this.list_target.appendChild( new_row );
    };
    };[/js]

    помогите плиз :?
     
  2. topas

    topas Активный пользователь

    С нами с:
    16 авг 2006
    Сообщения:
    2.258
    Симпатии:
    36
    PHP:
    1. <?php
    2. // В PHP 4.1.0 и более ранних версиях следует использовать $HTTP_POST_FILES
    3. // вместо $_FILES.
    4.  
    5. $uploaddir = '/var/www/uploads/';
    6. $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
    7.  
    8. print "<pre>";
    9. if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    10.     print "File is valid, and was successfully uploaded. ";
    11.     print "Here's some more debugging info:\n";
    12.     print_r($_FILES);
    13. } else {
    14.     print "Possible file upload attack!  Here's some debugging info:\n";
    15.     print "Possible file upload attack!  Дополнительная отладочная информация:\n";
    16.     print_r($_FILES);
    17. }
    18. print "</pre>";
    19.  
    20. ?>
    Пойдет?

    Оригинал
     
  3. Kreker

    Kreker Старожил

    С нами с:
    8 апр 2007
    Сообщения:
    5.433
    Симпатии:
    0
    topas
    Только в его случае будет $_FILES['userfile'][]...

    Чего-то мультиселектор какой-то большой оО