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
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";
		}
	}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.