habn porblem mitm datei upload und zwar möchte ich 5 dateien gleichzeitig bzw nacheinander hochladen und wollte das mit ner foreach schleife machen , allerdings klamm es nicht , weder mit dem hochladen noch mit dem in den richtigen ordner verschieben ,
hier ma mein code,.
<form enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF']?>" method="post">
<?php $pfad = $_SERVER['DOCUMENT_ROOT']; echo "Serverpfad: $pfad"; ?>
<table width="500" class="form">
<tr>
<td>Bild^1</td>
<td><input type="file" name="pictures[]" /></td>
</tr>
<tr>
<td>Bild^2</td>
<td><input type="file" name="pictures[]" /></td>
</tr>
<tr>
<td>Bild^3</td>
<td><input type="file" name="pictures[]" /></td>
</tr>
<tr>
<td>Bild^4</td>
<td><input type="file" name="pictures[]" /></td>
</tr>
<tr>
<td>Bild^5</td>
<td><input type="file" name="pictures[]" /></td>
</tr>
<tr>
<td colspan="2" align="center"> <input name="submit" type="submit" class="button" value="Auto eintragen" />
<input type="hidden" name="submited" value="save" />
<input type="hidden" name="submit" value="Upload" />
<input name="submit2" type="reset" class="button" value="Reset Fomular" /></td>
</tr>
</table>
</form>
<?php
if($_POST['submit'])
{
foreach ($_FILES['pictures']["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
move_uploaded_file(
$_FILES['pictures']['tmp_name'][$key],
"../uploaded". $_FILES['pictures']['name'][$key]
);
}
}
?>
warum denn so?! ôO
foreach ($_FILES['pictures']["error"] as $key => $error) {
-->
foreach ($_FILES['pictures'] as $key => $error) {
keine ahnung das hab ich so im inet gefunden :D
mhh komisch ich kann nur max3 bilder hochladen , und manchmal funzt es manchmal gehts aber auch nicht ,. obwohl die bildernamen in meinem array stehen wenn ich vardump mache,.
so hier mein code:
var_dump($_FILES);
foreach ($_FILES['pictures'] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
move_uploaded_file(
$_FILES['pictures']['tmp_name'][$key],
$uploaddir. $_FILES['pictures']['name'][$key]
);
}
}
so das array!
array(1) {
["pictures"]=>
array(5) {
["name"]=>
array(5) {
[0]=>
string(23) "bild1.jpg"
[1]=>
string(11) "bild2.jpg"
[2]=>
string(27) "bild3.jpg"
[3]=>
string(11) "bild4.jpg"
[4]=>
string(0) ""
}
["type"]=>
array(5) {
[0]=>
string(0) ""
[1]=>
string(0) ""
[2]=>
string(0) ""
[3]=>
string(10) "image/jpeg"
[4]=>
string(0) ""
}
["tmp_name"]=>
array(5) {
[0]=>
string(0) ""
[1]=>
string(0) ""
[2]=>
string(0) ""
[3]=>
string(28) "E:\xampp\xampp\tmp\php38.tmp"
[4]=>
string(0) ""
}
["error"]=>
array(5) {
[0]=>
int(2)
[1]=>
int(2)
[2]=>
int(2)
[3]=>
int(0)
[4]=>
int(4)
}
["size"]=>
array(5) {
[0]=>
int(0)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(14324)
[4]=>
int(0)
}
}
}
und ich habe festgestellt das wenn ich das [error] wie franky sagte weglasse, es kein bild mehr hochläd?!
kommt mir bekannt vor. hab ich auch mal in netz gefunden. musste es etwas anpassen und so funzt es nun bei mir:
foreach ($_FILES["upload"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
move_uploaded_file(
$_FILES["upload"]["tmp_name"][$key],$dir_upload.$_FILES["upload"]["name"][$key]
);
}
}
mhh funzt irgendwie nich so richtig bei mir aufem lokalserver