javascript - 我可以使用 SSH 压缩托管空间中的文件夹吗?
问题描述
我可以使用 SSH 和一些代码压缩托管空间中的文件夹吗?
它是给客户的,所以我不能告诉他们使用公钥/putty/commands/ftp,我想给他们一个 URL,例如http://yourdomain.com/createbackup,这样整个文件夹就会被压缩并被下载.
谢谢,任何帮助/指导将不胜感激。
解决方案
仔细阅读这个命令行,它将在 linux 上运行,就像后端的 putty 一样
<?php
header('Content-type: application/zip');
$create_zip = shell_exec('sudo zip -r backup.zip FolderName');
//backup.zip is your file , apply check this file does exit or not
$zip_file='backup.zip';
if(file_exists($zip_file)):
header('Content-Disposition: attachment; filename="'.basename($zip_file).'"');
header("Content-length: " . filesize($zip_file));
header("Pragma: no-cache");
header("Expires: 0");
ob_clean();
flush();
readfile($zip_file);
unlink($zip_file);
else:
echo 'Somthing went wrong please try again;'
推荐阅读
- python - 使用 Google Cloud Vision API 从申请表中提取手写文本
- dart - 列表视图中的gridview导致另一个异常被抛出:RenderBox was not layout: RenderViewport#45df5 NEEDS-LAYOUT NEEDS-PAINT
- javascript - 如何使用 JS 访问 Bokeh (Python) 变量?
- html - 使用 css 在图像顶部嵌入单词
- animation - 在 glTF2 网格中处理多个原始项目?
- http - 尽管包含了必要的参数,但 OpenWeatherMap 未返回指标
- java - 如何计算溢出值的输出
- lotus-domino - NotesJsonNavigator 和国际字符
- android - 使用密码和提供者创建 Firebase 用户
- javascript - 为什么 JavaScript try/finally 阻塞会导致函数明显返回两次?