<form action="upload.php" enctype="multipart/form-data" method="post"> <input type="file" name="zipFile" accept="zip/*"> <input type="submit" name="Submit" value="Submit"> </form>
$rand = rand(10,100); $streplaceFileName = cleanSpecialCharacters($_FILES[‘zipFile’][‘name’]); $zipFile = $rand."-".$streplaceFileName;$ds = DIRECTORY_SEPARATOR; $storeFolder = ‘uploads/zip’; if((!empty($_FILES)) && !empty($_FILES[‘zipFile’][‘name’])) { if(preg_match(‘/[.](zip)$/’, $_FILES[‘zipFile’][‘name’])) { $filename = $rand . "-" . $streplaceFileName; $tempFile = $_FILES[‘zipFile’][‘tmp_name’]; $targetPath = $storeFolder . $ds; $targetFile = $targetPath.$filename; $check = move_uploaded_file($tempFile,$targetFile); if($check) echo "ZipFile Uploaded Successfully!"; } } function cleanSpecialCharacters($string) { $string = str_replace(‘ ‘, ‘-‘, $string); // Replaces all spaces with hyphens. return preg_replace(‘/[^A-Za-z0-9.\-]/’, ", $string); // Removes special chars. }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)