我发现这个代码带有一个zip文件并将其解压缩。但是我遇到了一些错误。当我尝试上传zip时,我收到此错误Warning: ZipArchive::extractTo(): Permission denied in /Applications/XAMPP/xamppfiles/htdocs/newLosani/testphp.php on line 26
我将文件和文件夹的权限更改为777和644,但都没有工作:(
我甚至尝试将我上传到777的文件的权限更改为无效。
以下是相关代码:
<?php
if($_FILES["zip_file"]["name"]) {
$filename = $_FILES["zip_file"]["name"];
$source = $_FILES["zip_file"]["tmp_name"];
$type = $_FILES["zip_file"]["type"];
$name = explode(".", $filename);
$accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed');
foreach($accepted_types as $mime_type) {
if($mime_type == $type) {
$okay = true;
break;
}
}
$continue = strtolower($name[1]) == 'zip' ? true : false;
if(!$continue) {
$message = "The file you are trying to upload is not a .zip file. Please try again.";
}
$target_path = $filename; // change this to the correct site path
if(move_uploaded_file($source, $target_path)) {
$zip = new ZipArchive();
$x = $zip->open($target_path);
if ($x === true) {
$zip->extractTo("/zip/"); // change this to the correct site path
$zip->close();
unlink($target_path);
}
$message = "Your .zip file was uploaded and unpacked.";
} else {
$message = "There was a problem with the upload. Please try again.";
}
echo $message;
}
?>