Mime类型不起作用

时间:2014-02-22 20:32:29

标签: php mime-types

我搜索了mime类型的zip,apk文件,但它们对我不起作用(根据我编写的代码提供错误 - 无效格式。)。我跟随下面的代码,其他mime类型的允许扩展名工作正常。在下面的代码中我出错了什么?

$USER = $_COOKIE['phne'];
include 'config.php';

$sqli="SELECT * FROM `table*` WHERE EMAIL='$USER'";

$permquery=mysql_query($sqli);

$rows[35]=mysql_fetch_assoc($permquery);
echo '<a href="#"><img src="imagelogo*"></a><br>';
$allowedExts = array("gif", "jpeg", "jpg", "png" , "3gp" , "mp3" , "mp4", "apk", "zip"); 
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == 

"image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == 

"image/pjpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]

["type"] == "image/png") || ($_FILES["file"]["type"] == "video/3gpp") || ($_FILES

["file"]["type"] == "audio/mpeg") || ($_FILES["file"]["type"] == "video/mp4") || 

($_FILES["file"]["type"] == "application/vnd.android.package-archive") || ($_FILES

 ["file"]["type"] == "'application/x-zip-compressed' , 'application/octet-stream' , 

 'multipart/x-zip', 'application/x-compressed'") ) && ($_FILES["file"]["size"] < 

  1500000) && in_array($extension, $allowedExts)) 
  {
  if ($_FILES["file"]["error"] > 0)
{ echo "Return Code: <a><b>" . $_FILES["file"]["error"] . "</a></b><br>"; }
else 
    {
 echo " <h1>Your Upload Status</h1><br>";
echo " Dear, "; 
 echo "<a><b>"; 
echo $rows[35][FNAME]." ".$rows[35][LNAME];
echo "</b></a>";
echo " Your Uploaded file is : <a><b>" . $_FILES["file"]["name"] . "</a></b><br>";
echo "Uploded file Format is: <a><b>" . $_FILES["file"]["type"] . "</a></b><br>";
echo "Your file Size is: ";
echo "<a><b>"; 
 echo ($_FILES["file"]["size"] / 1024) ; 
  echo " KB <br></a></b>";  
  echo "<br>";
 echo "Your Email connected is ";
 echo "<a><b>";
echo $USER ;
echo "</a></b><br>";

 if (file_exists("location*/" . $USER . "/" . $_FILES["file"]["name"])) 
 {  echo " <h1>Final Status</h1><br><b>Sorry Upload failed.</b><br><a><b>File 

    already exists,Use different name .</b></a>"; 
     exit(); 
  } 
     else 
      {  move_uploaded_file($_FILES["file"]["tmp_name"], "location*/" . $USER . "/" . 

  $_FILES["file"]["name"]);  echo "<h1>Final Status</h1><br><b>Successfully Stored 

    to Kelkars.com :</b><br> " . "Your Successfully Uploaded File-"; 
     echo "<a><b>"; 
      echo $_FILES["file"]["name"];
       exit();
           } 
     }
   } 
      else { echo "<a>Invalid file-Sorry,This file Format not supported</a>";  
  exit();
    } 

任何帮助都将全部谢谢。

2 个答案:

答案 0 :(得分:0)

尝试打印apk和zip返回的文件类型

尝试以下方法⇩

将此添加到

application/vnd.android.package-archive     apk
application/zip  zip

AddType application/vnd.android.package-archive .apk
AddType application/zip  .zip

文件mime.types位于 {APACHE_INSTALL_PATH} / conf /,并将httpd.conf中的AddType行添加到其他AddType行附近 将其添加到/etc/apache2/mods-available/mime.conf:

答案 1 :(得分:0)

根据PHP manual type不是可靠的信息(它是从浏览器发送的):

  

文件的mime类型,如果浏览器提供此信息。一个例子是“image / gif”。但是,在PHP方面没有检查这个mime类型,因此不会将其值视为理所当然。

基本上......问题出在浏览器端,而不是服务器端,但你可以check the file type manually