使用刚刚创建了帐户的用户的电子邮件创建一个文件夹,并使用php显示用户电子邮件文件夹中的图像

问题描述 投票:0回答:1

我写了一个php代码,当一个新用户在网站上创建一个帐户时,将自动创建一个文件夹,并将用户电子邮件地址作为文件夹名称,现在该文件夹中有一个图像(即C://localhost/wecojo/[email protected]/pp/image.jpg)。

注意:有一个代码可以删除@ gmail.com(即C://localhost/wecojo/mikelawson/pp/image.jpg)。

正在尝试从用户([email protected])文件夹显示图像,但未显示。

它一直显示来自第一个用户([email protected])文件夹的图像。

The code below is for creating the folder:
// Finally, register user if there are no errors in the form
  if (count($errors) == 0) {
    $email = mysqli_real_escape_string($db, $_POST['email']);
    $nest = $email; 

    if ($user['email'] !== $email) {
      $userfname = substr($email, 0, strpos($email, '@'));
      (!mkdir($userfname, 0777, true));
    }

    $password = md5($password_1);//encrypt the password before saving in the database

    $query = "INSERT INTO users (username, email, user_number, password) 
              VALUES('$username', '$email', '$user_number', '$password')";
    mysqli_query($db, $query);
    $_SESSION['username'] = $username;
    $_SESSION['success'] = "You are now logged in";
    header('location: index.php');
  }
The below is for displaying the image(s):
$email = "";


$base_url = 'http://localhost/wecojo/';
$userfname = substr($email, 0, strpos($email, '@'));
$dir = $userfname."*/pp/*";

$files = glob($dir);
usort( $files, function( $a, $b ) { return filemtime($b) - filemtime($a); } );
$i = 1;
foreach($files as $file) {
$remove_ext = substr($file, 0, strrpos($file, "."));
  if($i <= 1 AND $i >= 1){
    echo '<img src="'.$base_url.$file.'" alt="'.$remove_ext.'" style="width:45px;height:45px;border-radius:10px;"></br>';
  }
 $i++;
}

我希望输出为:

img src="http://localhost/wecojo/mikelawson/pp/pouvoir 046.jpg" 
alt="maxillarious/pp/pouvoir 046" "

不是这个:

img src="http://localhost/wecojo/maxillarious/pp/pouvoir 046.jpg" 
alt="maxillarious/pp/pouvoir 046""
php email directory filenames subdirectory
1个回答
0
投票

您如何设置$ email变量?因为我在您编写的代码中什么都看不到。也放置(在foreach之前):

var_dump($files);

并粘贴输出

© www.soinside.com 2019 - 2024. All rights reserved.