upload + komenatarze

0

napisalem skrypt ktory uploaduje 4 pliki graficzne. Tzn. zrobilem ze uploaduje 1 bo nie wiem jak zmienic kod php zeby robil 4 pliki a nie tylko jeden z formularza.

mam 2 pliki:
dodaj.htm w ktorym jest formluarz uploadu 4 zdjec
[HTML]








</p> <form name="form1" method="post" action="sprawdz.php" enctype="multipart/form-data">
Opis zdjęcia:

Jego treść opublikowana będzie pod obrazkiem.

  <td width="287" height="50" align="center" class="form">
   <p align="center"><textarea rows="3" name="image_opis" cols="30" id="item_opis" type"text" ></textarea></td>
</tr>

<tr>
  <td width="387" height="38" class="form2"><strong>Nazwa firmy:</strong></td>
  <td width="287" height="38" align="center" class="form2"><input type="text" name="image_uzytkownik" id="image_uzytkownik" size="27">
  
  </td>
</tr>
<tr>
  <td width="387" height="60" class="form"><strong>Wybierz zdjęcie:</strong></td>
  <td width="287" height="60" align="center"><input name="image_filename" type="file" id="image_filename"></td>
</tr>
<tr>
  <td width="387" height="15" colspan="2"></td>
</tr>
<tr>
  <td width="387" height="50" valign="middle" class="form2"><strong>Opis zdjęcia:
  </strong>        <p>
    <p class="style1">Jego treść opublikowana będzie pod obrazkiem.</td>
  <td width="287" height="50" align="center" class="form2">
   
    <p align="center"><textarea rows="3" name="image_opis" cols="30" id="image_opis" type"text" ></textarea></td>
</tr>
<tr>
  <td width="387" height="60"><strong>Wybierz zdjęcie:</strong></td>
  <td width="287" height="60" align="center" class="form"><input name="image_filename" type="file" id="image_filename"></td>
</tr>
<tr>
  <td width="387" height="34" colspan="2"></td>
</tr>
<tr>
  <td width="387" height="50" class="form2"><strong>Opis zdjęcia:</strong>
    <p>
    <p class="style1">Jego treść opublikowana będzie pod obrazkiem.</td>
  <td width="287" height="50" align="center" class="form2">
   
    <p align="center"><textarea rows="3" name="image_opis" cols="30" id="image_opis" type"text" ></textarea></td>
</tr>
<tr>
  <td width="387" height="60" class="form"><strong>Wybierz zdjęcie:</strong></td>
  <td width="287" height="60" align="center" class="form"><input name="image_filename" type="file" id="image_filename" ></td>
</tr>
<tr>
  <td width="387" height="29" colspan="2"></td>
</tr>
<tr>
  <td width="387" height="50" valign="middle" class="form2"><strong>Opis zdjęcia:</strong>        <p>        
    <p class="style1">Jego treść opublikowana będzie pod obrazkiem.</td>
  <td width="287" height="50" align="center" class="form2">
   
    <p align="center"><textarea rows="3" name="image_opis" cols="30" id="image_opis" type"text" ></textarea></td>
</tr>
<tr>
  <td width="387" height="60" class="form" ><strong>Wybierz zdjęcie</strong>:</td>
  <td width="287" height="60" align="center" class="form"><input name="image_filename" type="file" id="image_filename" ></td>
</tr>
<tr>
  <td height="48" colspan="2" align="right"><input type="submit" name="Submit" value="Wyślij"> 
    <input type="reset" name="Submit2" value="Kasuj"></td>
  </tr>
<tr align="center">
  <td height="33" colspan="2" class="form2" align="center">Przyjmowane są zdjęcia w formacie: GIF, JPG/JPEG, PNG, których waga nie przekrasza <strong>400 kb</strong> </td>
  </tr>
<tr>
  <td width="387" height="53"></td>
  <td width="287" height="53"></td>
</tr>
</table> </form> </span>
[/HTML]

plik spradz.php spradza i przesyla zdjeca z formularza- przesyla tylko 1 a nie 4.
<?php
//polaczenie z baza danych
$link = mysql_connect("localhost", ".......","......")
or die("brak polaczenia" . mysql_error());
mysql_select_db("................", $link)
or die (mysql_error());

//udostepnianie zmiennych
$image_opis = $_POST['image_opis'];
$image_uzytkownik = $_POST['image_uzytkownik'];
$image_tempname = $_FILES['image_filename']['name'];
$today = date("Y-m-d");

//umieszczenie obrazu i sprzwdzenie jego formatu
$ImageDir = "http://trucker.v24.pl/3/images/";

$ImageName = $image_tempname;
if (move_uploaded_file($_FILES['image_filename']['tmp_name'], $ImageName))
{
//pobranie informacji na temat umieszczonego obrzau

list($width, $height, $type, $attr) = getimagesize($ImageName);

switch ($type)
{
case 1:
$ext = ".gif";
break;
case 2:
$ext = ".jpg";
break;
case 3:
$ext = ".png";
break;
default:
echo "Zle rozszerzenie pliku";
}

//wstawienie informacji do tabeli images
$insert = "INSERT INTO images (image_opis, image_uzytkownik, image_data)
VALUES
('$image_opis', '$image_uzytkownik', '$today')";
$insertresults = mysql_query($insert)
or die(mysql_error());

$lastpicid = mysql_insert_id();
$newfilename = $ImageDir . $lastpicid . $ext;
rename($ImageName, $newfilename);
}
?>

<html> <head> <title>Gotowe</title> </head> <body> Gotowe <?php echo $lastpicid . $ext; ?"> </body> </html>

Baza danych wyglada tak:
<?php
$sql = "CREATE TABLE IF NOT EXISTS images (

image_id INT(11) NOT NULL AUTO_INCREMENT,
image_opis VARCHAR(255) NOT NULL,
image_uzytkownik VARCHAR(255) NOT NULL,
image_data DATE NOT NULL,
PRIMARY KEY (image_id)
)";
?>
[b]
czy ktos moglby powiedziec jak zrobic zeby przsylal wiecej niz jeden plik ??[/b] 😟

0

post pow to moj ;) zapomnialem hasla do konta.
Poza tym skrypt cos nie chce przesylac plikow ani zapisywac danych w bazie dopiero teraz to zobaczylem :(

POMOCY :O

0

zmień w formularzu np image_uzytkownik na image_uzytkownik[]
image_filename na image_filename[] itd, a potem w skrypcie php

<?php
//polaczenie z baza danych
$link = mysql_connect("localhost", ".......","......")
or die("brak polaczenia" . mysql_error());
mysql_select_db("................", $link)
or die (mysql_error());


//udostepnianie zmiennych
for($i = 0; $i < count($_POST['image_opis']); $i++){
  $image_opis = $_POST['image_opis'][$i];
  $image_uzytkownik = $_POST['image_uzytkownik'][$i];
  $image_tempname = $_FILES['image_filename'][$i]['name'];
  $today = date("Y-m-d");

//umieszczenie obrazu i sprzwdzenie jego formatu
  $ImageDir = "http://trucker.v24.pl/3/images/";
 
  $ImageName = $image_tempname;
  if (move_uploaded_file($_FILES['image_filename']['tmp_name'], $ImageName)) {
//pobranie informacji na temat umieszczonego obrzau

    list($width, $height, $type, $attr) = getimagesize($ImageName);

    switch ($type) {
      case 1:
        $ext = ".gif";
        break;
      case 2:
        $ext = ".jpg";
        break;
      case 3:
        $ext = ".png";
        break;
      default:
        echo "Zle rozszerzenie pliku";
     }
 
//wstawienie informacji do tabeli images
    $insert = "INSERT INTO images (image_opis, image_uzytkownik, image_data)
          VALUES
          ('$image_opis', '$image_uzytkownik', '$today')";
    $insertresults = mysql_query($insert)
      or die(mysql_error());

    $lastpicid = mysql_insert_id();
    $newfilename = $ImageDir . $lastpicid . $ext;
    rename($ImageName, $newfilename);
  }
}
?>
0

wprowadzilem zmiany i wygladaja one tak:

sprawdz.php

//udostepnianie zmiennych
for($i = 0; $i < count($_POST['image_opis']); $i++){
  $image_opis = $_POST['image_opis'][$i];
  $image_uzytkownik = $_POST['image_uzytkownik'][$i];
  $image_tempname = $_FILES['image_filename'][$i]['name'];
  $today = date("Y-m-d");

//umieszczenie obrazu i sprzwdzenie jego formatu
  $ImageDir = "http://trucker.v24.pl/3/images/";
 
  $ImageName = $image_tempname;
  if (move_uploaded_file($_FILES['image_filename']['tmp_name'], $ImageName)) {
//pobranie informacji na temat umieszczonego obrzau

    list($width, $height, $type, $attr) = getimagesize($ImageName);

    switch ($type) {
      case 1:
        $ext = ".gif";
        break;
      case 2:
        $ext = ".jpg";
        break;
      case 3:
        $ext = ".png";
        break;
      default:
        echo "Zle rozszerzenie pliku";
     }
 
//wstawienie informacji do tabeli images
    $insert = "INSERT INTO images (image_opis, image_uzytkownik, image_data)
          VALUES
          ('$image_opis', '$image_uzytkownik', '$today')";
    $insertresults = mysql_query($insert)
      or die(mysql_error());

    $lastpicid = mysql_insert_id();
    $newfilename = $ImageDir . $lastpicid . $ext;
    rename($ImageName, $newfilename);
  }
}
?>

dodaj.htm

<div align="center">
  <center>
  <br>
  <br>
  <br>
  <form name="form1" method="post" action="sprawdz.php" enctype="multipart/form-data">
    

  <table border="0" width="403" cellspacing="0" cellpadding="0">
    <tr>
      <td width="387" height="50" valign="middle" class="form" ><strong>Opis zdjęcia:
        </strong>
        <p>
        <p class="style1">Jego treść opublikowana będzie pod obrazkiem.</td>
  
      <td width="287" height="50" align="center" class="form">
       <p align="center"><textarea rows="3" name="image_opis[]" cols="30" id="item_opis_1" type"text" ></textarea></td>
    </tr>

    <tr>
      <td width="387" height="38" class="form2"><strong>Nazwa firmy:</strong></td>
      <td width="287" height="38" align="center" class="form2"><input type="text" name="image_uzytkownik[]" id="image_uzytkownik_1" size="27">
      
      </td>
    </tr>
    <tr>
      <td width="387" height="60" class="form"><strong>Wybierz zdjęcie:</strong></td>
      <td width="287" height="60" align="center"><input name="image_filename[]" type="file" id="image_filename_1"></td>
    </tr>
    <tr>
      <td width="387" height="15" colspan="2"></td>
    </tr>
    <tr>
      <td width="387" height="50" valign="middle" class="form2"><strong>Opis zdjęcia:
      </strong>        <p>
        <p class="style1">Jego treść opublikowana będzie pod obrazkiem.</td>
      <td width="287" height="50" align="center" class="form2">
       
        <p align="center"><textarea rows="3" name="image_opis[]" cols="30" id="image_opis_2" type"text" ></textarea></td>
    </tr>
    <tr>
      <td width="387" height="60"><strong>Wybierz zdjęcie:</strong></td>
      <td width="287" height="60" align="center" class="form"><input name="image_filename[]" type="file" id="image_filename_2"></td>
    </tr>
    <tr>
      <td width="387" height="34" colspan="2"></td>
    </tr>
    <tr>
      <td width="387" height="50" class="form2"><strong>Opis zdjęcia:</strong>
        <p>
        <p class="style1">Jego treść opublikowana będzie pod obrazkiem.</td>
      <td width="287" height="50" align="center" class="form2">
       
        <p align="center"><textarea rows="3" name="image_opis[]" cols="30" id="image_opis_3" type"text" ></textarea></td>
    </tr>
    <tr>
      <td width="387" height="60" class="form"><strong>Wybierz zdjęcie:</strong></td>
      <td width="287" height="60" align="center" class="form"><input name="image_filename[]" type="file" id="image_filename_3" ></td>
    </tr>
    <tr>
      <td width="387" height="29" colspan="2"></td>
    </tr>
    <tr>
      <td width="387" height="50" valign="middle" class="form2"><strong>Opis zdjęcia:</strong>        <p>        
        <p class="style1">Jego treść opublikowana będzie pod obrazkiem.</td>
      <td width="287" height="50" align="center" class="form2">
       
        <p align="center"><textarea rows="3" name="image_opis[]" cols="30" id="image_opis_4" type"text" ></textarea></td>
    </tr>
    <tr>
      <td width="387" height="60" class="form" ><strong>Wybierz zdjęcie</strong>:</td>
      <td width="287" height="60" align="center" class="form"><input name="image_filename[]" type="file" id="image_filename_4" ></td>
    </tr>
    <tr>
      <td height="48" colspan="2" align="right"><input type="submit" name="Submit" value="Wyślij"> 
        <input type="reset" name="Submit2" value="Kasuj"></td>
      </tr>
    <tr align="center">
      <td height="33" colspan="2" class="form2" align="center">Przyjmowane są zdjęcia w formacie: GIF, JPG/JPEG, PNG, których waga nie przekrasza <strong>400 kb</strong> </td>
      </tr>
    <tr>
      <td width="387" height="53"></td>
      <td width="287" height="53"></td>
    </tr>
  </table>
    </form>
  </center>
</div>


ale nadal nie przysla zdjecia, ani nic nie dopisuje do bazdy :(

1 użytkowników online, w tym zalogowanych: 0, gości: 1