Du befindest Dich im Archiv vom ABAKUS Online Marketing Forum. Hier kannst Du Dich für das Forum mit den aktuellen Beiträgen registrieren.

Suche Bilder hochladen Script

Ajax, Hijax, Microformats, RDF, Markup, HTML, PHP, CSS, MySQL, htaccess, robots.txt, CGI, Java, Javascript usw.
pikus
PostRank 1
PostRank 1
Beiträge: 2
Registriert: 13.05.2007, 19:49

Beitrag von pikus » 13.05.2007, 19:54

dieser script kann nur bilder zu einer bestimmten grösse hochladen
liegt es vieleicht an meinem funpic webspace?
oder an dem Script?

Code: Alles auswählen

Hi, 

ich habe mich nochmal ran gesetzt und aus verschiedenen Codeschnipseln was zusammengebraut. 

Das Tool funktioniert ganz gut und kann hier mal getestet werden: 

www.maxrev.de/typenupload.php 

Sinn soll sein, dass ein Bild dass ich hochlade, einmal die vorgegebe Größe eines Vorschaubildes erreicht und einmal des großen Bildes, dass auch mit einer Angabe vorgegeben werden kann. 

Die Komprimierung liegt bei 70%. Das ist ein guter Komprimiss zwischen Qualität und Speicherplatz, wie ich finde. 

Es funktioniert bisher super mit .jpg, .jpeg & .png. Nur mit .gif habe ich zur Zeit das Problem, dass er bei den Thumbnails eine Fehleranzeige darstellt. Da muss noch irgendwo die Codezeile rein, dass ein "Ersatzbild" angezeigt wird. 

Oder kann man .gifs auch umwandeln in jpeg's ?! 

Code: 
<html> 
<head> 
<title>Upload</title> 
</head> 
<body> 
<? 
if&#40;$action&#41;&#123; 

   // -------------------------------- 
   // Diverse Variablen 
   // -------------------------------- 

$path = "images/typen/"; // Url zum Speicherordner der großen Bilder 
$thumb_path = "images/typen/thumb/"; // Url zum Speicherordner der Vorschaubilder 
$config_width = "320"; // Bildbreite max. bei großem Bild 
$config_height = "240"; // Bildhöhe max. bei großem Bild 
$config_thumb_width = "80"; // Bildbreite max. bei Vorschaubild 
$config_thumb_height = "60"; // Bildhöhe max. bei Vorschaubild 
$resizequality = "70"; // Bildkompressionsrate 0-100 
$deindomain = "http&#58;//www.maxrev.de/";  // unsere Domain 

if &#40;$HTTP_POST_FILES&#91;'userfile'&#93;&#91;'tmp_name'&#93;<> 'none'&#41; 
   &#123; 

   // -------------------------------- 
   // Get File Upload Info 
   // -------------------------------- 

         $filename = $HTTP_POST_FILES&#91;'pic_file'&#93;&#91;'name'&#93;; 
         $filetype = $HTTP_POST_FILES&#91;'pic_file'&#93;&#91;'type'&#93;; 
         $filetmp = $HTTP_POST_FILES&#91;'pic_file'&#93;&#91;'tmp_name'&#93;; 

   // -------------------------------- 
   // Check file type 
   // -------------------------------- 

   switch &#40;$filetype&#41; 
   &#123; 
      case 'image/jpeg'&#58; 
      case 'image/jpg'&#58; 
      case 'image/pjpeg'&#58; 

         $pic_filetype = '.jpg'; 
         break; 

      case 'image/png'&#58; 
      case 'image/x-png'&#58; 

         $pic_filetype = '.png'; 
         break; 

      case 'image/gif'&#58; 

         $pic_filetype = '.gif'; 
         break; 
      default&#58; 
         die&#40;"Falsches Dateiformat. Nur JPEG, GIF oder PNG erlaubt!"&#41;; 
   &#125; 

   // -------------------------------- 
   // Generate filename 
   // -------------------------------- 

   srand&#40;&#40;double&#41;microtime&#40;&#41;*1000000&#41;;   // for older than version 4.2.0 of PHP 

   do 
   &#123; 
      $pic_filename = md5&#40;uniqid&#40;rand&#40;&#41;&#41;&#41; . $pic_filetype; 
   &#125; 
   while&#40; file_exists&#40;$path . $pic_filename&#41; &#41;; 


   // -------------------------------- 
   // Move this file to upload directory 
   // -------------------------------- 

   $ini_val = &#40; @phpversion&#40;&#41; >= '4.0.0' &#41; ? 'ini_get' &#58; 'get_cfg_var'; 

   if &#40; @$ini_val&#40;'open_basedir'&#41; != '' &#41; 
   &#123; 
      if &#40; @phpversion&#40;&#41; < '4.0.3' &#41; 
      &#123; 
         die&#40;"open_basedir is set and your PHP version does not allow move_uploaded_file<br /><br />Please contact your server admin"&#41;; 
      &#125; 

      $move_file = 'move_uploaded_file'; 
   &#125; 
   else 
   &#123; 
      $move_file = 'copy'; 
   &#125; 

   $move_file&#40;$filetmp, $path . $pic_filename&#41;; 

   @chmod&#40;$path . $pic_filename, 0777&#41;; 


   // -------------------------------- 
   // Well, it's an image. Check its image size 
   // -------------------------------- 

   $pic_size = getimagesize&#40;$path . $pic_filename&#41;; 

   $pic_width = $pic_size&#91;0&#93;; 
   $pic_height = $pic_size&#91;1&#93;; 


   // -------------------------------- 
   // This image is okay, we can cache its thumbnail now 
   // -------------------------------- 

   if&#40;$pic_filetype != '.gif'&#41; 
   &#123; 
      $gd_errored = FALSE; 

      switch &#40;$pic_filetype&#41; 
      &#123; 
         case '.jpg'&#58; 
            $read_function = 'imagecreatefromjpeg'; 
            break; 
         case '.png'&#58; 
            $read_function = 'imagecreatefrompng'; 
            break; 
      &#125; 

      $src = @$read_function&#40;$path  . $pic_filename&#41;; 

      if &#40;!$src&#41; 
      &#123; 
         $gd_errored = TRUE; 
         $pic_thumbnail = ''; 
      &#125; 
      else if&#40; &#40;$pic_width > $config_thumb_width&#41; or &#40;$pic_height > $config_thumb_height&#41; &#41; 
      &#123; 
         // Resize it 
         if &#40;$pic_width > $pic_height&#41; 
         &#123; 
            $thumbnail_width = $config_thumb_width; 
            $thumbnail_height = $config_thumb_width * &#40;$pic_height/$pic_width&#41;; 
         &#125; 
         else 
         &#123; 
            $thumbnail_height = $config_thumb_height; 
            $thumbnail_width = $config_thumb_height * &#40;$pic_width/$pic_height&#41;; 
         &#125; 

         $thumbnail = @imagecreatetruecolor&#40;$thumbnail_width, $thumbnail_height&#41;; 

         $resize_function = 'imagecopyresampled'; 

         @$resize_function&#40;$thumbnail, $src, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $pic_width, $pic_height&#41;; 
      &#125; 
      else 
      &#123; 
         $thumbnail = $src; 
      &#125; 

      if &#40;!$gd_errored&#41; 
      &#123; 
         $pic_thumbnail = $pic_filename; 

         // Write to disk 
         switch &#40;$pic_filetype&#41; 
         &#123; 
            case '.jpg'&#58; 
               @imagejpeg&#40;$thumbnail, $thumb_path . $pic_thumbnail, $resizequality&#41;; 
               break; 
            case '.png'&#58; 
               @imagepng&#40;$thumbnail, $thumb_path . $pic_thumbnail&#41;; 
               break; 
         &#125; 

         @chmod&#40;$thumb_path . $pic_thumbnail, 0777&#41;; 

      &#125; // End IF $gd_errored 

   &#125; // End Thumbnail Cache 


  // -------------------------------------- 
  // OK lets resize the original picture 
  // -------------------------------------- 

  if&#40;$pic_filetype != '.gif'&#41; 
  &#123; 
    $gd_errored = FALSE; 

    switch &#40;$pic_filetype&#41; 
    &#123; 
      case '.jpg'&#58; 
        $read_function = 'imagecreatefromjpeg'; 
        break; 
      case '.png'&#58; 
        $read_function = 'imagecreatefrompng'; 
        break; 
    &#125; 

    $src = @$read_function&#40;$path  . $pic_filename&#41;; 

    if &#40;!$src&#41; 
    &#123; 
      $gd_errored = TRUE; 
      $pic_resize = ''; 
    &#125; 
    else if&#40; &#40;$pic_width > $config_width&#41; or &#40;$pic_height > $config_height&#41; &#41; 
    &#123; 
      // Resize it 
      if &#40; &#40;&#40;$pic_width / $pic_height&#41; > &#40;$config_width / $config_height&#41;&#41; &#41; 
      &#123; 
        $resize_width = $config_width; 
        $resize_height = $config_width * &#40;$pic_height/$pic_width&#41;; 
      &#125; 
      else 
      &#123; 
        $resize_height = $config_height; 
        $resize_width = $config_height * &#40;$pic_width/$pic_height&#41;; 
      &#125; 

      $resize = @imagecreatetruecolor&#40;$resize_width, $resize_height&#41;; 

      $resize_function = 'imagecopyresampled'; 

      @$resize_function&#40;$resize, $src, 0, 0, 0, 0, $resize_width, $resize_height, $pic_width, $pic_height&#41;; 
    &#125; 
    else 
    &#123; 
      $resize = $src; 
    &#125; 

    if &#40;!$gd_errored&#41; 
    &#123; 
      $pic_resize = $pic_filename; 

      // Write to disk 
      switch &#40;$pic_filetype&#41; 
      &#123; 
        case '.jpg'&#58; 
          @imagejpeg&#40;$resize, $path . $pic_resize, $resizequality&#41;; 
          break; 
        case '.png'&#58; 
          @imagepng&#40;$resize, $path . $pic_resize&#41;; 
          break; 
      &#125; 

      @chmod&#40;$path . $pic_resize, 0777&#41;; 

    &#125; // End IF $gd_errored 

  &#125; // End Picture Resize 

      echo "Datei ist auf dem Server! <br><br>"; 
      echo "Url des großen Bildes&#58; <a href=\"$deindomain$path$pic_filename\" target=\"_blank\">".$deindomain.$path.$pic_filename; 
     echo "</a> <br><img src=\"$deindomain$path$pic_filename\"><br><br>"; 
      echo "Url des Vorschaubildes&#58; <a href=\"$deindomain$thumb_path$pic_filename\" target=\"_blank\">".$deindomain.$thumb_path.$pic_filename; 
     echo "</a> <br><img src=\"$deindomain$thumb_path$pic_filename\">"; 

   &#125; 
&#125; else &#123; ?> 

<form method="post" enctype="multipart/form-data" action="<?php echo $PHP_SELF ?>"> 
<input type="hidden" name="MAX_FILE_SIZE" value="4000000"> 
<br> 
<strong>File Upload</strong> <br> 
<br> 
<input name="pic_file" type="file" size=40> 
<br> 
<br> 
<input type="submit" name="action" value="Speichern"> 
</form> 
<? 
 &#125; 
   // ----------------------------------------- 
   // Das Script kann unter Verwendung 
   // dieses Vermerks uneingeschränkt 
   // genutzt / verändert werden. 
   //  © www.marc-gutt.de 
   // ----------------------------------------- 
?> 
</body> 
</html> 

Anzeige von ABAKUS

von Anzeige von ABAKUS »

Content Erstellung von ABAKUS Internet Marketing
Ihre Vorteile:
  • einzigartige Texte
  • suchmaschinenoptimierte Inhalte
  • eine sinnvolle Content-Strategie
  • Beratung und Umsetzung
Jetzt anfragen: 0511 / 300325-0

crilla
PostRank 5
PostRank 5
Beiträge: 218
Registriert: 12.02.2007, 06:52

Beitrag von crilla » 13.05.2007, 21:25

***
Zuletzt geändert von crilla am 17.11.2016, 23:34, insgesamt 1-mal geändert.

CIX88
PostRank 3
PostRank 3
Beiträge: 90
Registriert: 11.05.2007, 11:45

Beitrag von CIX88 » 14.05.2007, 14:20

$HTTP_POST_FILES
Warum benutzt man veraltete Variablen ?
Ab PHP6 wird diese Script nicht mehr funktionieren.
Dafür gibt es nicht umsonst $_FILES... :D

Und dann gibt es noch ImageDestroy().
Man hat sich schon dabei etwas gedacht :D