내 FTP에 zip 파일을 업로드하고 자동으로 압축을 해제하는 데 사용하는 PHP 스크립트가 있습니다.FTP로 작동하는 PHP 스크립트를 만들 수 있습니까?
내 ftp에서 폴더와 파일을 삭제하는 완료된 PHP 스크립트가 있는지 궁금합니다.
이유 나는 로컬에서 압축을 풀지 않고 압축을 풀고 압축을 푸는 데 너무 많은 시간을 절약하고 파일을 업로드하기 때문에 묻습니다.
이제 내 문제는 Filezilla를 사용하여 폴더와 파일을 삭제하는 데 많은 시간이 걸리므로 속도를 높이고 싶습니다.
실무 솔루션을 갖고 계신 분? 편집
:
<?php
/* Simple script to upload a zip file to the webserver and have it unzipped
Saves tons of time, think only of uploading Wordpress to the server
Thanks to c.bavota (www.bavotasan.com)
I have modified the script a little to make it more convenient
Modified by: Johan van de Merwe (12.02.2013)
*/
function rmdir_recursive($dir) {
foreach(scandir($dir) as $file) {
if ('.' === $file || '..' === $file) continue;
if (is_dir("$dir/$file")) rmdir_recursive("$dir/$file");
else unlink("$dir/$file");
}
rmdir($dir);
}
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.";
}
/* PHP current path */
$path = dirname(__FILE__).'/'; // absolute path to the directory where zipper.php is in
$filenoext = basename ($filename, '.zip'); // absolute path to the directory where zipper.php is in (lowercase)
$filenoext = basename ($filenoext, '.ZIP'); // absolute path to the directory where zipper.php is in (when uppercase)
$targetdir = $path . $filenoext; // target directory
$targetzip = $path . $filename; // target zip file
/* create directory if not exists', otherwise overwrite */
/* target directory is same as filename without extension */
if (is_dir($targetdir)) rmdir_recursive ($targetdir);
mkdir($targetdir, 0777);
/* here it is really happening */
if(move_uploaded_file($source, $targetzip)) {
$zip = new ZipArchive();
$x = $zip->open($targetzip); // open the zip file to extract
if ($x === true) {
$zip->extractTo($targetdir); // place in the directory with same name
$zip->close();
unlink($targetzip);
}
$message = "Your .zip file was uploaded and unpacked.";
} else {
$message = "There was a problem with the upload. Please try again.";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Unzip a zip file to the webserver</title>
</head>
<body>
<?php if($message) echo "<p>$message</p>"; ?>
<form enctype="multipart/form-data" method="post" action="">
<label>Choose a zip file to upload: <input type="file" name="zip_file" /></label>
<br />
<input type="submit" name="submit" value="Upload" />
</form>
</body>
</html>
그래서 FTP 서버에 연결하고 PHP 스크립트를 통해 zip 파일을 업로드하고 있습니다. 그게 효과가 있다면 PHP를 통해 FTP 서버의 파일도 삭제하지 않으시겠습니까? http://www.php.net/manual/en/function.ftp-delete.php (압축을 푼 후 곧바로 실행하지 마십시오. 업로드 된 zip 파일의 경우 cron에서 수행하십시오. 예를 들어 1 시간 이상 경과하십니까?) – Latheesan
방금 압축 해제 스크립트를 찾았습니다. 삭제를위한 완성 된 PHP 스크립트를 찾고 있습니다. 나는 프로그래밍에 대해 아무 것도 모릅니다 ... – Behedwin
코드를 게시하여 현재 수행중인 작업을 볼 수 있습니까? – Latheesan