我试图在我的本地MAMP服务器上传和解压缩.zip文件。 上传工作得很好。但是文件(名为decomp.zip)并没有上传,尽管我得到了#34; woot!"回声。
这是test.php中的相关功能:
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$FileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
$zip = new ZipArchive;
$res = $zip->open('decomp.zip');
if ($res === TRUE) {
$zip->extractTo('/uploads/extracted/');
$zip->close();
echo 'woot!';
} else {
echo 'doh!';
}
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
以下表格:
<form action="test.php" method="post" enctype="multipart/form-data">
<textarea name="name" rows="2" cols="20"> </textarea >
<input type="submit" value="Submit" />
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload zip" name="submit">
</form>
有人可以帮忙吗?