我想解压缩一个文件,这工作得很好
system('unzip File.zip');
但我需要通过URL传递文件名,不能让它工作,这就是我所拥有的。
$master = $_GET["master"];
system('unzip $master.zip');
我错过了什么?我知道一定是我忽视的小而愚蠢的事情。
谢谢你!
我想解压缩一个文件,这工作得很好
system('unzip File.zip');
但我需要通过URL传递文件名,不能让它工作,这就是我所拥有的。
$master = $_GET["master"];
system('unzip $master.zip');
我错过了什么?我知道一定是我忽视的小而愚蠢的事情。
谢谢你!
当前回答
只改变
system('unzip $master.zip');
到这个
system('unzip ' . $master . '.zip');
或者这个
系统(“{$大师}. zip解压缩”);
其他回答
我更新了Morteza Ziaeemehr的答案,以一个更干净和更好的代码,这将解压一个文件提供的形式到当前目录使用DIR。
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' >
<title>Unzip</title>
<style>
body{
font-family: arial, sans-serif;
word-wrap: break-word;
}
.wrapper{
padding:20px;
line-height: 1.5;
font-size: 1rem;
}
span{
font-family: 'Consolas', 'courier new', monospace;
background: #eee;
padding:2px;
}
</style>
</head>
<body>
<div class="wrapper">
<?php
if(isset($_GET['page']))
{
$type = $_GET['page'];
global $con;
switch($type)
{
case 'unzip':
{
$zip_filename =$_POST['filename'];
echo "Unzipping <span>" .__DIR__. "/" .$zip_filename. "</span> to <span>" .__DIR__. "</span><br>";
echo "current dir: <span>" . __DIR__ . "</span><br>";
$zip = new ZipArchive;
$res = $zip->open(__DIR__ . '/' .$zip_filename);
if ($res === TRUE)
{
$zip->extractTo(__DIR__);
$zip->close();
echo '<p style="color:#00C324;">Extract was successful! Enjoy ;)</p><br>';
}
else
{
echo '<p style="color:red;">Zip file not found!</p><br>';
}
break;
}
}
}
?>
End Script.
</div>
<form name="unzip" id="unzip" role="form">
<div class="body bg-gray">
<div class="form-group">
<input type="text" name="filename" class="form-control" placeholder="File Name (with extension)"/>
</div>
</div>
</form>
<script type="application/javascript">
$("#unzip").submit(function(event) {
event.preventDefault();
var url = "function.php?page=unzip"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
dataType:"json",
data: $("#unzip").serialize(), // serializes the form's elements.
success: function(data)
{
alert(data.msg); // show response from the php script.
document.getElementById("unzip").reset();
}
});
return false; // avoid to execute the actual submit of the form
});
</script>
</body>
</html>
简单地尝试这个yourDestinationDir是目的地提取到或删除-d yourDestinationDir提取到根目录。
$master = 'someDir/zipFileName';
$data = system('unzip -d yourDestinationDir '.$master.'.zip');
就用这个吧:
$master = $_GET["master"];
system('unzip' $master.'.zip');
在代码中,$master作为字符串传递,系统将寻找一个名为$master.zip的文件
$master = $_GET["master"];
system('unzip $master.zip'); `enter code here`
只改变
system('unzip $master.zip');
到这个
system('unzip ' . $master . '.zip');
或者这个
系统(“{$大师}. zip解压缩”);
使用getcwd()在同一目录中进行解压缩
<?php
$unzip = new ZipArchive;
$out = $unzip->open('wordpress.zip');
if ($out === TRUE) {
$unzip->extractTo(getcwd());
$unzip->close();
echo 'File unzipped';
} else {
echo 'Error';
}
?>