2017-04-30 9 views
1

何らかの理由で、IEとEdgeでは "application/png"と表示されますが、ChromeとFirefoxでは "image/png"と表示されます。私はいくつかの異なった画像を試しました、jpegsは同じことをします。これは正常ですか? "application/png"のアカウントや説明文を含めるべきですか?または私は何か間違っているのですか?PHPイメージタイプ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

[MIME拡張子のファイル拡張子](http://stackoverflow.com/questions/7349473/php-file-upload-mime-or-extension-based-verification)を確認してください。 – shaggy

答えて

0

異なるブラウザとオペレーティングシステムによって、異なるMIMEタイプが提供されます。代わりにアップロードされたファイルにhttp://php.net/getimagesizeを使用し、IMG_PNG、IMG_JPG、IMG_GIFの場合で$ getimagesizeresult [2]をオンにして、適切なMIMEタイプを独自に適用するべきです。

関連する問題