W tym temacie (założyłem nowy bo nie wiem czy ktokolwiek przegląda rozwiązane) miałem problem z odczytaniem pól formularza. Wystarczyło tylko zamienić $pole na $_POST['pole']. Teraz chcę to samo zrobić dla kodu uploadu obrazków na serwer.
Mam to:
<form action="addnews.php" method="post" enctype="multipart/form-data"> [...] <input type="hidden" name="MAX_FILE_SIZE" value="1048576" /> <div id="images"> <input type="file" name="img[]" size="50" class="upload" /> </div> <input type="button" value="Więcej..." onclick="add_element('images');" /> [...] </form> [...] <?php { { if($ext == 'jpg' || $ext == 'jpeg' || $ext == 'png' || $ext == 'gif') //przyjmuj tylko takie pliki { move_uploaded_file($_FILES['img']['tmp_name'][$i],$imgdir.'/'.$_FILES['img']['name'][$i]); //skopiuj plik na serwer [...] } } } ?>
funkcja add_element wygląda tak
function add_element(container) //dodaje element do listy zdjęć { var mark = document.createElement('input'); mark.setAttribute('type', 'file'); mark.setAttribute('name', 'img[]'); mark.setAttribute('size', '50'); mark.className = 'upload'; var container = document.getElementById(container); container.appendChild(mark); }
I chciałbym ten kod przerobić tak, żeby tablicę $img odczytać z formularza przez tablicę POST.
Próbowałem $img = $_POST['img'] i $img = $_POST['img[]'] niestety bez skutku.