Jump to content

2 Questions About Zip Files


Zero3X

Recommended Posts

First what are the possible $_FILES['file']['type'] s of .zip. I know one is "application/x-zip-compressed" but are there any others (basically I need to check if the uploaded file is a .zip?

Second question; how could I extract the contents of .zip to a directory on the server without the use of FTP?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/220623-2-questions-about-zip-files/
Share on other sites

Thanks for the help.

 

Could someone tell me if this would work? I'm not near my server right now so I can't test it myself.

<?php
if($_GET['action'] == "uploadtheme") {
    //Check if the upload is a .zip
	if($_FILES['themeupload']['type'] == "file/zip" or $_FILES['themeupload']['type'] == "application/x-zip-compressed" or $_FILES['themeupload']['type'] == "application/zip") {
		//Create temp directory, move zip to it.
		mkdir("themes/temp", 0777);
		$target = "themes/temp".basename($_FILES['themeupload']['name']) ; 
		move_uploaded_file($_FILES['themeupload']['tmp_name'], $target);
		//Extract zip and check if theme.php exists
		$zip = new ZipArchive;
		$location = $zip->open($target);
		if ($location === TRUE) {
			$zip->extractTo("themes/temp/themeextract");
			$zip->close();
		} else {
			echo "Failed to extract.";
		}
		if (file_exists("themes/temp/themeextract/theme.php")) {
			include("themes/temp/themeextract/theme.php");
			if (!isset($theme_author)) {
				$theme_name = "Unknown author";
			}
			if (!isset($theme_name)) {
				$random = rand(0, 9999999);
				$theme_name = "Unknown Name ".$random;
			}
			//Move theme folder, delete temp.
			rename("themes/temp/themeextract", "themes/".$theme_name);
			if (file_exists("themes/".$theme_name."/theme.php")) {
				//Insert values into database
			} else {
				echo "Failed to move theme from temp";
			}
		} else {
			echo "Failed to find theme.php";
		}
	}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.