Rozdiel medzi ukladaním jedného obrázku a viacerých obrázkov je len v obsahu superglobálneho poľa $_FILES, ak si na stránke spravil formulár, kde je viacero upload položiek, toto pole bude mať trošku inú štruktúru.
Ako príklad, takýto formulár:
Kód:
<form enctype='multipart/form-data' method='post'>
<input type='file' name='subor[]'><br>
<input type='file' name='subor[]'><br>
<input type='file' name='subor[]'><br>
<input type='file' name='subor[]'><br>
<input type='file' name='subor[]'><br>
<input type='submit' value='ok'>
</form>
vyrobí (napríklad) takéto pole $_FILES:
Kód:
Array
(
[subor] => Array
(
[name] => Array
(
[0] => 1-m.JPG
[1] => 3-m.JPG
[2] => 2-m.JPG
[3] => 4a7025a7-f178-49d4-bc27-102446cb2140.jpg
[4] => 4a52055f-6e0c-482a-a504-037046cb2140.jpg
)
[type] => Array
(
[0] => image/jpeg
[1] => image/jpeg
[2] => image/jpeg
[3] => image/jpeg
[4] => image/jpeg
)
[tmp_name] => Array
(
[0] => C:\wamp\tmp\php5AE4.tmp
[1] => C:\wamp\tmp\php5AE5.tmp
[2] => C:\wamp\tmp\php5AE6.tmp
[3] => C:\wamp\tmp\php5AE7.tmp
[4] => C:\wamp\tmp\php5AE8.tmp
)
[error] => Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 0
[4] => 0
)
[size] => Array
(
[0] => 4385
[1] => 4458
[2] => 4887
[3] => 11715
[4] => 30954
)
)
)
Iný formulár:
Kód:
<form enctype='multipart/form-data' method='post'>
<input type='file' name='subor1'><br>
<input type='file' name='subor2'><br>
<input type='file' name='subor3'><br>
<input type='file' name='subor4'><br>
<input type='file' name='subor5'><br>
<input type='submit' value='ok'>
</form>
vyrobí iné pole (s inou štruktúrou):
Kód:
Array
(
[subor1] => Array
(
[name] => 1-m.JPG
[type] => image/jpeg
[tmp_name] => C:\wamp\tmp\php5AFA.tmp
[error] => 0
[size] => 4385
)
[subor2] => Array
(
[name] => 1-v.JPG
[type] => image/jpeg
[tmp_name] => C:\wamp\tmp\php5AFB.tmp
[error] => 0
[size] => 34357
)
[subor3] => Array
(
[name] => 2-m.JPG
[type] => image/jpeg
[tmp_name] => C:\wamp\tmp\php5AFC.tmp
[error] => 0
[size] => 4887
)
[subor4] => Array
(
[name] => 2-v.JPG
[type] => image/jpeg
[tmp_name] => C:\wamp\tmp\php5AFD.tmp
[error] => 0
[size] => 38123
)
[subor5] => Array
(
[name] => 3-m.JPG
[type] => image/jpeg
[tmp_name] => C:\wamp\tmp\php5AFE.tmp
[error] => 0
[size] => 4458
)
)
No a napokon sa to dá aj kombinovať:
Kód:
<form enctype='multipart/form-data' method='post'>
<input type='file' name='subor1'><br>
<input type='file' name='subor2'><br>
<input type='file' name='subor3[]'><br>
<input type='file' name='subor3[]'><br>
<input type='file' name='subor3[]'><br>
<input type='submit' value='ok'>
</form>
vyrobí takéto pole $_FILES
Kód:
Array
(
[subor1] => Array
(
[name] => 1-m.JPG
[type] => image/jpeg
[tmp_name] => C:\wamp\tmp\php5B0A.tmp
[error] => 0
[size] => 4385
)
[subor2] => Array
(
[name] => 2-m.JPG
[type] => image/jpeg
[tmp_name] => C:\wamp\tmp\php5B0B.tmp
[error] => 0
[size] => 4887
)
[subor3] => Array
(
[name] => Array
(
[0] => 1-v.JPG
[1] => 3-m.JPG
[2] => 4a701c54-d4c0-4c1e-8d1f-102446cb2140.jpg
)
[type] => Array
(
[0] => image/jpeg
[1] => image/jpeg
[2] => image/jpeg
)
[tmp_name] => Array
(
[0] => C:\wamp\tmp\php5B0C.tmp
[1] => C:\wamp\tmp\php5B0D.tmp
[2] => C:\wamp\tmp\php5B0E.tmp
)
[error] => Array
(
[0] => 0
[1] => 0
[2] => 0
)
[size] => Array
(
[0] => 34357
[1] => 4458
[2] => 4385
)
)
)
Takže, podľa toho, aký máš formulár, si uprav skript pre jeden upload - jednoducho tam pridaj jeden cyklus. Nie je to nič ťažké, informácie hľadaj v
prvej téme v PHP sekcii a v
PHP manuáli.
_________________
A. S. Tanenbaum píše:
The terms LF, MF, and HF refer to low, medium, and high frequency, respectively. Clearly, when the names were assigned, nobody expected to go above 10 MHz, so the higher bands were later named the Very, Ultra, Super, Extremely, and Tremendously High Frequency bands. Beyond that there are no names, but Incredibly, Astonishingly, and Prodigiously high frequency (IHF, AHF, and PHF) would sound nice.