PHP - Moved: Unzip Script?
This topic has been moved to Miscellaneous.
http://www.phpfreaks.com/forums/index.php?topic=342772.0 Similar TutorialsHi. I'm attaching a script bellow which is free to be modified. When we use this, we can extract a file in root directory by default, but i wanna set it to extract in subdirectory (i wanna use it for my custom hosting panel for my users) So please modify its default extract folder to /users/$id Thanks. I have a wierd issue that I cant quite pin down. Here is my code Code: [Select] if(isset($_GET['world']) && ($_GET['world'] == "upload")) { $foldername = $_POST['worldname']; $target = "worlduploads/"; $ok=1; $allowed_types = array("application/octet-stream","application/zip","application/x-zip"); $allowed_extensions = array("zip"); if ($_FILES['file']['size'] > 262144000) { $max_size = round(25600); echo "Your file is too large. Maximum file size is 250MB. <br>"; $ok=0; } if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; $ok=0; } else { $path_parts = pathinfo(strtolower($_FILES["file"]["name"])); if(in_array($_FILES["file"]["type"],$allowed_types) && in_array($path_parts["extension"],$allowed_extensions)) { $filename = $_FILES["file"]["name"]; } else { echo "Type " . $_FILES["file"]["type"] . " with extension " . $path_parts["extension"] . " not allowed <br />"; $ok=0; } } if($ok == 1) { move_uploaded_file($_FILES["file"]["tmp_name"], $target . $filename); $file_location = $target . $filename; if(file_exists($file_location)) { mkdir('worlduploads/'.$foldername.''); //create local $dir = 'worlduploads/'.$foldername.'/'; $zip = zip_open($file_location); while($zip_entry = zip_read($zip)) { $entry = zip_entry_open($zip,$zip_entry); $filename = zip_entry_name($zip_entry); $target_dir = $dir.substr($filename,0,strrpos($filename,'/')); $filesize = zip_entry_filesize($zip_entry); if (is_dir($target_dir) || mkdir($target_dir)) { if ($filesize > 0) { $contents = zip_entry_read($zip_entry, $filesize); file_put_contents($dir.$filename,$contents); } } } } else { echo "There was a problem saving the file. <br />"; } } } The idea is, the user enters a file name and upload there zip file, once uploaded this then unzips to a specified directory. This works fine if all the files are contained within the root of the zip, however if I try to upload a zip that contains folders then I just get Error: 1 displayed. I removed the unzip function and this is happening with just the upload. I would have thought that php would just copy the zip byte by byte without investigating its structure? I have tested my unzip with zips that contain folders and it works fine, maintains structure and puts the files where it should, its just the upload error that is giving me problems! PHP.ini is also set to 250mb Thanks for any insights Hi i have a few sites all with the same html and file struture what i want to be able to do is make a script that connects to one of my servers downloads a zip file with new updates to old html documents then unzip it and the users server and replace all exsiting data with new zip content. bit like user->clicks->update->downloads via aother server->unzips->replace old files with new ones i am think of using curl to download the files but i would not have a clue where to start with this one btw the zip files is around 2.3mb Dear sirs, I need to upload files to FTP and To waste less time, I zip the files, but the problem that since it is Automation it zips with directory - like this C:/DIR.zip in zip file I have a DIR/files.... How to unzip all files to main directory on the server. Right now if the main dir is /main/html/ it unzips to /main/html/dir/files But I need /main/html/files Thank you. This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=348869.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=322742.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=310049.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=318755.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=343070.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=319561.0 This topic has been moved to Beta Test Your Stuff!. http://www.phpfreaks.com/forums/index.php?topic=352359.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=320494.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=334372.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=313684.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=321105.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=322839.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=307535.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=314681.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=351532.0 This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=331047.0 |