Bild Upload

So hab mal ein bisschen gegoogelt und gelesen habe den Code etwas verändert und jetzt liest er bei 2 ausgewählten Bilder schon mal beide arryas aus z.b:
Code:
Array ( [datei] => Array ( [0] => Array ( [name] => logo.png [type] => image/png [tmp_name] => /tmp/phpVlnaOs [error] => 0 [size] => 45068 ) [1] => Array ( [name] => watermark.gif [type] => image/gif [tmp_name] => /tmp/phpW6xKlf [error] => 0 [size] => 550 ) ) )

hier mal der Code :
PHP:
<style type="text/css">
    body {
	background-image: url(/skin/my/images/mainbg.jpg);
	background-repeat: repeat;
}
    body p {
	text-align: center;
	color: #333;
}
.auto-style2 {
	text-align: center;
}

</style>
<?php  
include ("../checkuser.php");  
include ("../config.inc.php"); 
function multiple(array $_files, $top = TRUE)
{
    $files = array();
    foreach($_files as $datei=>$file){
        if($top) $sub_datei = $file['name'];
        else    $sub_datei = $datei ;
        
        if(is_array($sub_datei )){
            foreach(array_keys($sub_datei ) as $key){
                $files[$datei][$key] = array(
                    'name'     => $file['name'][$key],
                    'type'     => $file['type'][$key],
                    'tmp_name' => $file['tmp_name'][$key],
                    'error'    => $file['error'][$key],
                    'size'     => $file['size'][$key],
                );
                $files[$datei ] = multiple($files[$datei ], FALSE);
            }
        }else{
            $files[$datei ] = $file;
        }
    }
    return $files;
}

$files = multiple($_FILES);
print_r($files);
$id = $_SESSION["user_id"]; 
 $albumname = $_POST["albumid"];
$dateityp = GetImageSize($_FILES['datei']['tmp_name']);
$bild = $_FILES['datei']['name']; 
$datei = $_FILES['datei']['name']; // Dies hab ich noch nicht getestet, da ich den Namen immer nach datum und user id abgespeichert hab. 
$datei = str_replace(" ", "_", "$datei"); 
$datei = htmlentities($datei); // Mit leerzeichen -> _ hab ich auch noch nicht getestet, sollte aba klappen 
$dateityp = GetImageSize($_FILES['datei']['tmp_name']);
$erlaubte_Dateiendungen = array( "jpg", "JPEG" );




$i = 0;
while($i < count($files)) { 

               move_uploaded_file($_FILES['datei']['tmp_name'], "../users/$id/Gallery/album/$albumname/$datei"); 
                  $file        = "../users/$id/Gallery/album/$albumname/$datei"; 
                  $target    = "../users/$id/Gallery/album/$albumname/$datei"; 
                  $max_width   = "400"; //Breite ändern 
                  $max_height   = "300"; //Höhe ändern 
                  $quality     = "100"; //Qualität ändern (max. 100) 
                  $src_img     = imagecreatefromjpeg($file); 
                  $picsize     = getimagesize($file); 
                  $src_width   = $picsize[0]; 
                  $src_height  = $picsize[1]; 
                   
                  if($src_width > $src_height) 
                  { 
                  if($src_width > $max_width) 
                  { 
                    $convert = $max_width/$src_width; 
                    $dest_width = $max_width; 
                    $dest_height = ceil($src_height*$convert); 
                  } 
                  else 
                  { 
                    $dest_width = $src_width; 
                    $dest_height = $src_height; 
                  } 
                  } 
                  else 
                  { 
                  if($src_height > $max_height) 
                  { 
                    $convert = $max_height/$src_height; 
                    $dest_height = $max_height; 
                    $dest_width = ceil($src_width*$convert); 
                  } 
                  else 
                  { 
                    $dest_height = $src_height; 
                    $dest_width = $src_width; 
                  } 
                  } 
                  $dst_img = imagecreatetruecolor($dest_width,$dest_height); 
                  imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height); 
                  imagejpeg($dst_img, "$target", $quality); 
$i++;
         }      


$aendern = "UPDATE album  Set
albumbild = 'album/$albumname/$bild'
WHERE albumid = '$albumname'";
$update = mysql_query($aendern);

?>
 
Also, DEIN Array sieht also so aus: (Ich habe ihn mal formatiert damit man die Struktur OHNE KLAMMERN ZÄHLEN erkennt)
Code:
Array ( 
	[datei] => Array ( 
		[0] => Array ( 
			[name] => logo.png 
			[type] => image/png 
			[tmp_name] => /tmp/phpVlnaOs 
			[error] => 0 
			[size] => 45068 
		) 
		[1] => Array ( 
			[name] => watermark.gif 
			[type] => image/gif 
			[tmp_name] => /tmp/phpW6xKlf 
			[error] => 0 
			[size] => 550 
		) 
	) 
)

Ergo ist das hier sicher falsch
PHP:
while($i < count($files)) { 

               move_uploaded_file($_FILES['datei']['tmp_name'], "../users/$id/Gallery/album/$albumname/$datei"); 
...
}

Das sollte eher so aussehen
PHP:
foreach($_FILES['datei'] as $i => $details){
    move_uploaded_file($details['tmp_name'], "../users/$id/Gallery/album/$albumname/$datei"); 
...
}

Gut möglich das auch der Rest vom Code deinem Array falsch abwickelt.
 
Danke erstmal für deine mühe
habe es so gemacht geht aber auch

PHP:
foreach($_FILES['datei']['name'] as $key => $value){
 
Dann hast du ein anderes Array als du gepostet hast - ich gebs auf dir weiter zu helfen. Ich fühle mich verarscht. Ich reiss mir den A**** auf dir zu helfen und du lieferst dauernd sich widersprechende und somit FALSCHE Informationen.

Tschüss
 

Neue Beiträge

Zurück