The problem I am having is that when I try to upload a .zip file the program seems not to be able to associate the demanded .zip file with the allowed mime type for the .zip files, and thus jumps directly jumps to the else statement that fires the message that says: "Sorry, you cannot upload this type of file!", so most probably I have mentioned the mime type there in a wrong way, can you please show me the right way to do this? I tried : "application/zip" , "archive/zip" , and "file/zip" were all of these didn't work. While other files as specified above did work.
Here is the code for the Php script that is responsible for the upload and saving of the file. it is called: upload.php and path is the name of the chosen file:
<?php
if($_FILES["path"]["type"] == "image/gif"
|| $_FILES_["path"]["type"] == "image/jpeg"
|| $$_FILES["path"]["type"] == "application/zip" // problem in specifying the mime type here...
&& $_FILES["path"]["size"] < 100000) { // the limit is around 100 kb
if($_FILES["path"]["error"] > 0)
echo "An error has occured!".$_FILES["path"]["error"]."<br/ >";
else
echo "Upload: " . $_FILES["path"]["name"] . "<br />";
echo "Type: " . $_FILES["path"]["type"] . "<br />";
echo "Size: " . ($_FILES["path"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["path"]["tmp_name"];
echo '<script language = "javascript">
alert("The file has been successfully uploaded!");
</script>';
if (file_exists("upload/" . $_FILES["path"]["name"])) //checks if the file already exists in the directory
{
echo $_FILES["path"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["path"]["tmp_name"],
"upload/" . $_FILES["path"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["path"]["name"];
}
}
else // in case the above criteria was not met
echo '<script language = "javascript">alert("Sorry, you cannot upload this type of file!");</script>';
?>
Here is the file containing the form responsible for comunicating with the above script and for choosing the file, in case you need it:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>File Upload test</title>
<style type="text/CSS">
feildset{width : 20%; color:orange};
</style>
</head>
<body>
<center>
<form method = "post" name = "upload" action = "upload.php" enctype="multipart/form-data">
<feildset>
<label id = "title" name = "title">Enter the path to the file you want to upload!</label>
<br>
<br>
<label id="fileUpload">Upload:</label>
<input type = "file" name = "path" id = "path" size = "30">
<input type = "submit" name = "submit" value = "Upload!">
</feildset>
</form>
</center>
</body>
</html>
Any help, comments, tips , ideas and solutions are welcome, Thanks in advance
This post has been edited by ayman_mastermind: 05 July 2009 - 09:57 AM

New Topic/Question
Reply



MultiQuote




|