Question

I have searched mime types for zip,apk files but they are not working for me (gives error -invalid format as per my code written.) . I have following code with me , other mime types of allowed extensions are working perfectly.Whats going wrong for me in below code ?

$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();
    } 

Any help would be Thank full.

Était-ce utile?

La solution

Try printing the File Type returned by apk and zip

try below method too ⇩

add this to

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

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

the file mime.types is located at {APACHE_INSTALL_PATH}/conf/ , and add the AddType line in httpd.conf near other AddType lines add this to /etc/apache2/mods-available/mime.conf :

Autres conseils

According to PHP manual type isn't reliable information (it's sent from browser):

The mime type of the file, if the browser provided this information. An example would be "image/gif". This mime type is however not checked on the PHP side and therefore don't take its value for granted.

So basically... The issue is on the browsers side, not on servers side, but you can check the file type manually.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top