Zero3X Posted December 4, 2010 Share Posted December 4, 2010 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 Quote Link to comment Share on other sites More sharing options...
OldWest Posted December 4, 2010 Share Posted December 4, 2010 You can use preg_match() to read the file names in the dir to look for .zip. Quote Link to comment Share on other sites More sharing options...
OldWest Posted December 4, 2010 Share Posted December 4, 2010 And php is plentiful with zip tools: http://www.php.net/manual/en/function.ziparchive-open.php Quote Link to comment Share on other sites More sharing options...
Zero3X Posted December 4, 2010 Author Share Posted December 4, 2010 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"; } } } ?> Quote Link to comment Share on other sites More sharing options...
Zero3X Posted December 4, 2010 Author Share Posted December 4, 2010 Well, I tested it out and have a Fatal Error. Fatal error: Class 'ZipArchive' not found in ... on line 9. I guess it doesn't like me declaring a new ziparchive. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.