【发布时间】:2018-04-06 04:36:19
【问题描述】:
我不知道如何使用密码在 PHP 中压缩文件。密码将是时间和文件名。
这是我到目前为止所做的。
上传的 HTML 代码。
<form enctype="multipart/form-data" action="http://localhost/CSS/addfile.php" method="POST">
<div id="label">
<label>Upload File</label>
</div>
<input name="doc" type="file" placeholder="Upload File Here" accept="files/topsecret/*" required>
<input type="submit" value="Upload" name="submit">
</form>
PHP 代码
function GetImageExtension($filetype)
{
if(empty($filetype)) return false;
switch($filetype)
{
case 'files/topsecret/bmp': return '.bmp';
case 'files/topsecret/gif': return '.gif';
case 'files/topsecret/jpeg': return '.jpg';
case 'files/topsecret/png': return '.png';
case 'files/topsecret/txt': return '.txt';
case 'files/topsecret/doc': return '.doc';
case 'files/topsecret/docx': return '.docx';
case 'files/topsecret/pdf': return '.pdf';
default: return false;
}
}
$upFile = $_FILES['doc']['name'];
$tmp_name = $_FILES['doc']['tmp_name'];
$ftype = $_FILES['doc']['type'];
$fileExt = GetImageExtension($ftype);
$filename = $upFile.$fileExt;
$target_path="files/topsecret/".$filename;
move_uploaded_file($tmp_name,$target_path);
date_default_timezone_set('Asia/Kuala_Lumpur');
$timefile = date("F j, Y g:ia");
$size = filesize($target_path);
$size = number_format($size / 1024, 2) . ' KB';
try{
$sql = "INSERT INTO file(File_path,Date,Size,Name) VALUES ('".$target_path."','".$timefile."','".$size."','".$filename."')";
if ($connection->query($sql)){
echo"<script type= 'text/javascript'>alert('Upload Successfully');</script>";
header("refresh:2;index.php");
}else{
echo "<script type= 'text/javascript'>alert('Upload Not Successfully Inserted.');</script>";
}
我研究了一下,发现了一些 php 函数,但不知道如何使用它。 喜欢。 ZipArchive::setEncryptionName ...但不能使用它,因为我在 xampp 中使用的是 PHP 7.1.8 版。
请帮助我解释如何做到这一点,尽可能简单。我需要使用 zip 或 rar 使用密码加密上传的文件。计划将文件名和时间一起使用哈希,然后将其设置为密码。
非常感谢。
【问题讨论】:
-
您完全按照示例php.net/manual/en/ziparchive.setencryptionname.php中显示的方式使用它
-
我试过了,因为我的版本是 7.1.8,所以我无法使用它,因为我使用的是 xampp。未捕获的错误:调用未定义的方法 ZipArchive::setEncryptionName()
标签: php html encryption zip rar