I want to unzip a file and this works fine
system('unzip File.zip');
But I need to pass in the file name through the URL and can not get it to work, this is what I have.
$master = $_GET["master"];
system('unzip $master.zip');
What am I missing? I know it has to be something small and stupid I am overlooking.
Thank you,
Use below PHP code, with file name in the URL param "name"
Using
getcwd()
to extract in the same directoryPHP has its own inbuilt class that can be used to unzip or extracts contents from a zip file. The class is ZipArchive. Below is the simple and basic PHP code that will extract a zip file and place it in a specific directory:
If you want some advance features then below is the improved code that will check if the zip file exists or not:
Source: How to unzip or extract zip files in PHP?
Simply try this yourDestinationDir is the destination to extract to or remove -d yourDestinationDir to extract to root dir.
I updated answer of @rdlowrey to a cleaner and better code, This will unzip a file into current directory using
__DIR__
.Just use this:
in your code
$master
is passed as a string, system will be looking for a file called$master.zip