【发布时间】:2018-12-02 15:21:25
【问题描述】:
当用户注册时,我正在创建一个站点我解压缩了一个文件,该文件包含用户个人资料的当前文件夹结构。
文件夹结构以 zip /u/folders.zip 的形式保存在 users 目录中,我以为我正在创建以下结构:
-u
--folders.zip
--newamazingusername
---index.php
---folder1
---folder2
----subfolder1
----subfolder2
---folder3
它正在创造的是这样的:
-u
--folders.zip
--newamazingusername
---folders
----index.php
----folder1
----folder2
-----subfolder1
-----subfolder2
----folder3
处理文件:
<?php
require_once( "../../assets/inc/connection.php" );
if ( !empty($_GET['email']) && !empty($_GET['username']) ):
$get_username = $_GET['username'];
$get_email = $_GET['email'];
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$hash = **[REDACTED CODE] Assume I am Hashing my password properly**
$sql = "UPDATE users SET username='" . $get_username . "' WHERE email='" . $get_email . "'";
// use exec() because no results are returned
$conn->exec($sql);
$zip = new ZipArchive;
$fileLocation = $_SERVER['DOCUMENT_ROOT'] . '/u/folders.zip';
$newfile = $_SERVER['DOCUMENT_ROOT'] . '/u/' . $get_username . '.zip';
if (!copy($fileLocation, $newfile)) {
echo "failed to copy";
header('Location: http://' . $_SERVER['HTTP_HOST'] . '?error=foldercopyfail');
exit();
}
$res = $zip->open($newfile);
if ($res === TRUE) {
$zip->extractTo($_SERVER['DOCUMENT_ROOT'] . '/u/' . $get_username);
$zip->close();
header('Location: http://' . $_SERVER['HTTP_HOST'] . '/u/' . $get_username );
} else {
echo 'doh!';
}
unlink($newfile);
exit();
} catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
else :
header('Location: http://' . $_SERVER['HTTP_HOST'] . '?error=noaccess');
endif;
?>
我需要解压用户文件夹根目录下 zip 中的文件夹。我很确定如果 sn-p 是 copy() 的问题。
感谢您的帮助!
【问题讨论】:
-
根据您的 PDO 查询,我将假设您也错误地散列了您的密码。 PDO 查询应该使用准备好的语句,并参数化。这与问题无关,因此脚本的前 15 行也可以删除,最后 11 行也是如此。
-
folders.zip文件中文件夹的布局是什么? -
User3783243 - 感谢您的详细帮助。我实际上不再需要密码了。
-
Hasta - 这是一个 index.php 3 个文件夹,其中包含 index.php 文件和一个文件夹,其中包含 3 个空文件夹。
标签: php ziparchive