从cookie中获取邮件并添加到上传的文件名中

Getting email from cookie and adding to the uploaded file name

我有一个图库页面,用户可以选择上传他们的图片,但只有注册用户才能上传。所以当用户点击上传按钮时,上传页面会检查用户是否登录,如果他们没有登录,他们会被定向到这样的登录页面

<?php
session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
header("Location: ../login");
}
?>

我在登录页面上设置了这样的 cookie

$_POST['email'] = stripslashes($_POST['email']);
    $_POST['email'] = mysqli_real_escape_string($dbc, trim($_POST['email']));
    $_POST['password'] = mysqli_real_escape_string($dbc, trim($_POST['password']));
    $_POST['password'] = stripslashes($_POST['password']);
    $hour = time() + 3600;
    setcookie(ID_my_site, $_POST['email'], $hour);
    setcookie(Key_my_site, $_POST['password'], $hour);

我正在这样重命名上传的文件

//get photo credit and location
$credit = "CR".$_POST['credit'];
$location = "LOC".$_POST['location'];
//generate a random number and then generate a new file name with credit and     location
$new = rand(0000,9999);
$newfilename=$new.$credit.$location;

现在我想将用户电子邮件地址也添加到这个新文件名中。我试过了

$_COOKIE['ID_my_site']

但这不起作用。谁能告诉我怎么做?

我现在开始工作了。在设置cookie的登录时,我又添加了一行代码:

$_SESSION['email'] = $_POST['email'];

这会保存登录用户的电子邮件名称,当他上传文件时,我将上传者电子邮件地址添加到新文件名中,如下所示:

//get original file name
$file_name = $_FILES["fileToUpload"]["name"];

//get photo credit and location
$credit = "CR".$_POST['credit'];
$location = "LOC".$_POST['location'];

//get the user email from $_SESSION['email']
$uploader = $_SESSION['email'];

//generate a random number and then generate a new file name with credit and location and uploader name
$new = rand(0000,9999);
$newfilename=$new.$uploader.$credit.$location;