Hallo!
Ich gerade ein Script geschrieben, mit welchem ich ein Bild uploaden, und verkleinern kann. Jetzt möchte ich es umschreiben,
	
Mein PHP-Script:
	
							
						
					Ich gerade ein Script geschrieben, mit welchem ich ein Bild uploaden, und verkleinern kann. Jetzt möchte ich es umschreiben,
PHP-Code:
	
	
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>upload</title>
</head>
<body>
<form name="upload" action="upload_script.php" method="post" enctype="multipart/form-data" accept="image/    *.jpeg *.jpg *.jpe *.png *.gif" >
<?php
for($ii =0; $ii < 10; $ii++)
{
echo "<input type='file' name='datei[".$ii."]' /><br>\n";
}
?>
<input type="submit" name="up_sb">
</form>
</body>
</html>
PHP-Code:
	
	
<?
if(isset($_POST['up_sb']))
{
$asdf = $_POST['datei'];
echo $asdf;
echo "test";
}
if(is_uploaded_file($_FILES['datei']['tmp_name']))
{
    /*____________________________________________
    
                    Set the options
    ______________________________________________*/
    $width = 500; //<-width of the resized image
    $height = 600;    //<- height of the resized image
    $filename = $_FILES['datei']['tmp_name']; //<- the uploaded image temp-name        
    $path = "bild_test/"; //<- The path where the image should be saved
    $quality = 100;
    $files_par = "datei";
    // Set the chars which shuld be replaced 
    $search_pattern = array("/ /","/ä/","/ü/","/ö/","/-/");
    $replace_pattern = array("_","ae","ue","oe","_");
    $type = getimagesize($filename);
    // Creates the filename and replaces the whitespaces with an underscore
    $f_name = preg_replace($search_pattern,$replace_pattern,
strtolower(substr($_FILES[$files_par]['name'],0,strrpos
($_FILES[$files_par]['name'],"."))));
    if ($dir_handler = opendir($path)) 
    {
       while (false !== ($file = readdir($dir_handler))) //<- reads the files
       {
           $file = substr($file,0,strrpos($file,"."));
             if($file == $f_name) //<- if the file exists in the 
directory a suffix will be added
             {
                 $suffix = substr($file,-3);
                 settype($suffix,"integer"); //<- gets the 
number of the suffix f.e. "ds2" => 2
                 if($suffix == 0)
                 {
                     $f_name.="_001";
                 }
                 else //<- adds the suffix if the suffix-number is greater than 1
                 {
                 $suffix++;
                 $suffix = str_pad($suffix,3,0,STR_PAD_LEFT);
                 $suffix = "_".$suffix;
               $f_name = substr($f_name,0,strlen($f_name)-4).$suffix;
                 }
             }
       }
   closedir($dir_handler);
  }
    
    // Get new dimensions
    list($width_orig, $height_orig) = getimagesize($filename);
    if($width && ($width_orig < $height_orig)) 
    {
       $width = ($height / $height_orig) * $width_orig;
    } 
    else 
    {
       $height = ($width / $width_orig) * $height_orig;
    }    
        
    if($type[2] == 1) //<- GIF Image
    {
        echo "Gif datei";
    } 
    if($type[2] == 2) // <- JPEG Image
    {
    /*    // Content type
        header('Content-type: image/jpeg');
        // Resample */
        $image_tmp = imagecreatetruecolor($width, $height);
        $image = imagecreatefromjpeg($filename);
        imagecopyresampled($image_tmp, $image, 0, 0, 0, 0, 
$width, $height, $width_orig, $height_orig);
            // Output
        $flag = @imagejpeg($image_tmp,$path.$f_name.".jpg", $quality);
        if($flag == 1)
        {
            echo "Das Bild wurde upgeloadet!";
        }
        else
        {
            echo "Ein Fehler ist aufgetreten!";
        }
    }
    if($type[2] == 3)
    {
        echo "png file";
    }
}
?>
          
Kommentar