Reputation: 31
I want people to be able to upload zip files to my server. I have a form for them to upload to and it redirects to an upload page. I can successfully upload pictures (png and jpg) but whenever I try a zip I canot upload it, its not show me any error, Is there a way to accept the zip files?
<?php
function uploadfile()
{
$allowedExts = array("zip", "rar");
$split = explode(".",$_FILES["filework"]["name"]);
$type = strtolower($split[sizeof($split)-1]);
$rname = time().".".$type;
if (($_FILES["filework"]["type"] == "application/zip") || ($_FILES["filework"]["type"] == "application/x-zip") || ($_FILES["filework"]["type"] == "application/x-zip-compressed") && ($_FILES["filework"]["size"] < 20000000) && in_array($split, $allowedExts)) {
$destination = "uploads/".$rname;
$temp_file = $_FILES['filework']['tmp_name'];
move_uploaded_file($temp_file,$destination);
return $rname;
} else {
return $_FILES["filework"]["error"];}
}
}
?>
Upvotes: 3
Views: 1847
Reputation: 2591
try
in_array($type, $allowedExts)
also, nothing will be returned if your if
fails and no actual error is generated, see php documentation
And as DanFromGermany said the process of upload is as follows:
$temp_file = $_FILES['filework']['tmp_name'];
)action
page of the formBecause your php is executed last, it cannot check for file extension prior to upload, however you can just ignore the temp file if it doesn't meet criteria.
Upvotes: 1