2017-04-30 2 views
1

Aus irgendeinem Grund wird der Bildtyp als "application/png" in IE 7 und Edge, aber "image/png" in Chrome und Firefox angezeigt. Ich habe mehrere verschiedene Bilder ausprobiert, jpegs machen das gleiche. Ist das normal? Sollte ich eine oder eine Erklärung für die "Anwendung/PNG" angeben? Oder mache ich etwas falsch?PHP-Bildtyp application/png

 if ((($screenshot_type == 'image/gif') || ($screenshot_type == 'image/jpeg') || 
     ($screenshot_type == 'image/pjpeg') || ($screenshot_type == 'image/png')) && 
     (($screenshot_size > 0) && ($screenshot_size <= GW_MAXFILESIZE))) { 
     if ($_FILES['screenshot']['error'] == 0) { 

     // Move the file to the targe upload folder 
     $target = GW_UPLOADPATH . $screenshot; 
     if (move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)) { 
      // Connect to the database 
      $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) 
       or die('Unable to connect to databse'); 
      // Write the data to the database 
      $query = "INSERT INTO guitarwars VALUES (0, NOW(), '$name', '$score', '$screenshot')"; 
      mysqli_query($dbc, $query) 
       or die('Unable to complete query'); 

      // Confirm success with the user 
      echo '<p>Thanks for adding your new high score!</p>'; 
      echo '<p><strong>Name:</strong> ' . $name . '<br>'; 
      echo '<strong>Score:</strong> ' . $score . '</p>'; 
      echo '<img src="' . GW_UPLOADPATH . $screenshot . '" alt="Score image" /></p>'; 
      echo '<p><a href="index.php">&lt;&lt; Back to high scores</a></p>'; 

      // Clear the score data to clear the form 
      $name = ""; 
      $score = ""; 
      $screenshot = ""; 

      mysqli_close($dbc); 
     } 
     else { 
     echo '<p class="error">Sorry, there was a problem uploading your screen shot image.</p>'; 
     } 
    } 
    } 
    else { 
    echo '<p class="error">The screen shot must be a GIF, JPEG, or PNG image file no ' . 
     'greater than ' . (GW_MAXFILESIZE/1024) . ' KB in size.<br>' . $screenshot_size . '<br>' . $screenshot_type . '</p>'; 
    } 
+0

Sie überprüfen besser für [Dateierweiterung, als für Mime-Typ] (http://stackoverflow.com/questions/7349473/php-file-upload-mime-or-extension-based-verification). – shaggy

Antwort

0

Verschiedene Browser und Betriebssysteme liefern unterschiedliche MIME-Typen. Sie sollten stattdessen einfach http://php.net/getimagesize für die hochgeladene Datei verwenden und $ getimagesizeresult [2] mit Fällen für IMG_PNG, IMG_JPG, IMG_GIF einschalten und einen geeigneten MIME-Typ selbst anwenden.