【问题标题】:Create a folder with the email of the user that just created an account and display the image(s) that is in the user email's folder using php使用刚刚创建帐户的用户的电子邮件创建一个文件夹,并使用 php 显示用户电子邮件文件夹中的图像
【发布时间】:2020-01-28 14:47:19
【问题描述】:

我写了一个php代码,当一个新用户在网站上创建一个帐户时,会自动创建一个以用户电子邮件地址作为文件夹名称的文件夹,现在文件夹中有一个图像(即C://localhost/vern/mikelawson@gmail.com/zeco/image.jpg) .

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

我正在尝试显示来自用户 (mikelawson@gmail.com) 文件夹的图像,但它没有显示。

它一直显示来自第一个用户 (mikelawson@gmail.com) 文件夹的图像。

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/vern/';
$userfname = substr($email, 0, strpos($email, '@'));
$dir = $userfname."*/zeco/*";

$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/vern/mikelawson/zeco/pouvoir 046.jpg" 
alt="mikelawson/zeco/pouvoir 046" "

不是这个:

img src="http://localhost/mikelawson/zeco/pouvoir 046.jpg" 
alt="mikelawson/zeco/pouvoir 046""

【问题讨论】:

    标签: php email directory filenames subdirectory


    【解决方案1】:

    如何设置 $email 变量?因为我在你写的那段代码中看不到任何东西。 也放置(在 foreach 之前):

    var_dump($files);
    

    并粘贴输出

    【讨论】:

      猜你喜欢
      • 2013-07-26
      • 1970-01-01
      • 2020-06-10
      • 2013-06-10
      • 2022-11-07
      • 1970-01-01
      • 1970-01-01
      • 2019-07-17
      • 1970-01-01
      相关资源
      最近更新 更多